I am trying to copy all the line items in the item sublist in one sales order to another new sales order. I am getting all the line items and while setting the line items I have followed the order shown below:
Price level
Item
Quantity
Amount
Tax Code
The issue is that all the values are set correctly but the amount and tax code fields are not set. Is this the correct order to set the line item fields? If not, what is the order that I should follow so that lines commit successfully?
var set=currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value:salesOrd_item[j]
});
alert('item is being set');
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value:salesOrd_quantity[j]
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'units',
value:salesOrd_units[j]
});
alert('units are being set');
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value:salesOrd_taxcode[j]
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'price',
value:salesOrd_pricelevel[j]
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
value:salesOrd_rate[j]
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'amount',
value:salesOrd_amount,
});
One thing to consider is that the Rate (and therefore Amount) are dependant on the Price Level. You cannot set a Price Level and then also set a custom Rate that is different than the Price Level, NetSuite will not allow this in the UI or via SuiteScript. If you're trying to copy a line from another order just copy in the Price Level and Quantity, the Rate and Amount will auto update.
This leads to a second consideration. When you fill a field in on a line, often times other fields are slaved to that field. This happens asynchronously, so if you fill in a slaved field before it gets updated by NetSuite, your value will be overwritten. This might be happening to your tax field. To avoid this, NetSuite added a property called fireSlavingSync to ensure that each setValue on a line waits till all slaved actions have completed before executing your next line of code. Try editing your lines to add this extra parameter like this:
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value:salesOrd_item[j],
fireSlavingSync: true
});
Related
I have a client script runs on Suitelet.
On Suitelet we have a sublist which has many select columns.
Let's say we have Select 1 and Select 2.
Select 2 options should be different if you change the option in Select 1.
Could this be done in Client Script? or in that Suitelet?
Any help would be appreciated.
`
var select1= sublist.addField({
id: 'custpage_select1',
label: 'Select1',
type: ui.FieldType.SELECT
});
var select2= sublist.addField({
id: 'custpage_select2',
label: 'Select2',
type: ui.FieldType.SELECT
});
`
In client script when the field is changed, I want to change options of Select 2 depend on Select 1.
function fieldChanged(scriptContext){
if(scriptContext.fieldId=="custpage_select1"){
let page = currentRecord.get();
var select2 = page.getField({fieldID:"custpage_select2"});
select2.removeSelectOption({value:"value1"});
}
}
But this shows me an error that
Cannot read properties of null
Thank you
Yes. You can use the N/currentRecord module in your client script with getField() and removeSelectOption().
let page = currentRecord.get();
const select2 = page.getField({
fieldId: 'custpage_select2'
});
select2.removeSelectOption({
value: 'option1'
});
I am facing a weird problem where my code (specifically a record.save action) does not seem to be executed. The code is located in the 'reduce' phase of a suitescript 2.0 map/reduce script.
I have no clue what the cause for this might be. The logging does display 'is this executed' as stated in the example below but the lines below that do not seem to be executed. The logging does not show 'Order lines marked for order with ID:
//load the order
var SOrecord = record.load({
type: record.Type.SALES_ORDER,
id: orderId,
isDynamic: false
});
setLineValues(SOrecord, values, newShipmentId)
log.debug('Is this executed?');
//Save Order
var recId = SOrecord.save({enableSourcing: false, ignoreMandatoryFields: true});
log.debug('Order lines marked for order with ID: ', recId)
return recId;
Can anyone help?
UPDATE
//load the order
var SOrecord = record.load({
type: record.Type.SALES_ORDER,
id: orderId,
isDynamic: false
});
log.debug('Order Loaded! ', SOrecord);
//Loop lines present in values array
for(var i = 0; i < values.length; i++){
//Generate Shipment Line ID, 3 digits starting at 001
var tmpShipmentLineId = i + 1
var shipmentLineId = tmpShipmentLineId.toString().padStart(3, '0');
log.debug('Shipment Line ID: ', shipmentLineId)
//check if first fulfillment is done, if yes mark ready for second fulfillment
if(SOrecord.getSublistValue({sublistId: 'item', fieldId: 'custcol_il_send_ff_interface', line: values[i]}) == true){
log.debug('Line: ' + i, 'Mark ready for 2nd fulfillment')
//Set values
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_send_to_ff_2nd',
line: Number(values[i]),
value: true
});
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_shipment_id_2nd',
line: Number(values[i]),
value: newShipmentId
});
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_shipment_line_id_2nd',
line: Number(values[i]),
value: shipmentLineId
});
}
//If not, mark ready for first fulfillment
else{
log.debug('Line: ' + i, 'Mark ready for first fulfillment')
//Set Values
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_il_send_ff_interface',
line: Number(values[i]),
value: true
});
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_shipment_id',
line: Number(values[i]),
value: shipmentId
});
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_shipment_line_id',
line: Number(values[i]),
value: shipmentLineId
});
}
};
log.debug('SOrecord after changes: ', SOrecord);
SOrecord.save();
log.debug('Record Saved ', 'END');
Above you'll find an extended code snippet, for some reason all code outside of the for loop does not seem to be executed... Any ideas?
I'm not sure I understand the setup of the code here... the text refers to the first code snippet but the second one seems more informative. Here are some general things I would try but if you clarify what is printing and what is not on the second code snippet maybe I can help more...
(1) Add a try catch for better error handling. You seem to be getting a error that's not being logged.
(2) Try loading the record in dynamic mode and using selectLine -> setCurrentSublistValue -> commitLine
(3) it seems you are using "line: values:[i]" I don't have a example of what that returns but it seems it should be "line: i"
(4) have you logged this - SOrecord.getSublistValue({sublistId: 'item', fieldId: 'custcol_il_send_ff_interface', line: values[i]}) - if not please do and let us know what the value is...
I have a suitelet that is creating an order. Most times this works but sometimes, maybe 1 in 50 it fails with this error. "Please enter a value for amount."
The error is thrown when sommitting this.
if(orderLine.amount){
log.debug("itemrate", orderLine.itemrate);
salesOrder.setCurrentSublistValue({
sublistId : 'item',
fieldId : 'rate',
value : Number(orderLine.itemrate ? orderLine.itemrate : (orderLine.amount / orderLine.qty))
});
fieldServices.sleep(1000);
log.debug("Amount", orderLine.amount);
salesOrder.setCurrentSublistValue({
sublistId : 'item',
fieldId : 'amount',
value : Number(orderLine.amount)
});
}
The logs on a fail execution reads
2 View Debug Amount 26/05/2020 11:21 AM -System- 118.0909090909091
3 View Debug itemrate 26/05/2020 11:21 AM -System- 118.0909
So the amount is getting set with an amount but when I try to commit the line it doesn't work 100% of the time.
So here was the problem. I assumed the logging was on the line that I posted but it turned out it was trying to add another line with the amount of 0. JavaScript being JavaScript saw 0 as false in
if(orderLine.amount)
so the amount was never added to the line. I changed this if statement to read
if(orderLine.amount || orderLine.amount == 0)
This solved the problem.
I would like to copy a few lines of the sales order "item" sublist and insert them into another sales order.
For now I have just found N/record.insertLine(sublistId, lineNr, ignoreRecalc), but I can't see how this function could help me because it doesn't take any data.
My use case is that I have a sales order out of which I have to generate other sales orders, but only containing some of the items of the original sales order.
I think you need these two to work with.
Get Sublist
...
var objField = objRecord.getSublistField({
sublistId: 'item',
fieldId: 'item',
line: 3
});
Set Sublist
objRecord.setSublistValue({
sublistId: 'item',
fieldId: 'item',
line: 3,
value: true
});
I want to show serial number as first column in jqgrid.since, database records doesn't has contigous 'ids', I can't use it.
Is there any simple way to accomplish this?
Update:
sample code:
$(document).ready(function()
{
$("#list").jqGrid(
{
url:'<%=Url.class_variable_get(:##baseurl) %>/address_books/show.json',
datatype:'json',
mtype:'get',
colNames:['Id','Name','Email Id','Number'],
colModel:[
{name:'address_book_id',index:'address_book_id',sorttype:'int',sortable:true,width:100},
{name:'name',index:'name',sortable:true,width:300},
{name:'email',index:'email',sortable:true,width:265},
{name:'number',index:'number',sorttype:'int',sortable:true,width:300},
],
pager:$('#pager'),
emptyrecords: "No Records to display",
pginput:true,
pgbuttons:true,
rowNum:10,
rowList:[5,10,20,30],
viewrecords:true,
sortorder: "desc",
//multiselect:true,
loadonce:true,
gridview:false,
sortname:'name',
caption: " Contacts List",
jsonReader: {
repeatitems : false,
cell:"",
id: "0"
},
height: 80
});
$("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search:true},{multipleSearch:true});
});
This question/answer should contain information on how to redraw the jqgrid based on redefined table data: jqGrid add new column
Regarding the addition of a you might add a time stamp to each of the records, or even the value of a counter; something like:
var recordsSet = [];
$.each(databaseRecords, function(i, record) {
record.idx = Date.now();
record._id = i;
recordSet.push(record);
});
/* code to populate or redraw using update recordSet array jqgrid here */
You shoud then be able to assign either the _id field or the idx field (sample property names only) to the index property of your column models in the call to jqgrid.