0
votes

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:

  1. Price level
  2. Item
  3. Quantity
  4. Amount
  5. 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,

});
1

1 Answers

1
votes

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
});