0

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 Answer 1

1

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
});
Sign up to request clarification or add additional context in comments.

2 Comments

yeah i did exactly the way you said it worked for rate and amount but the tax code is not getting set it populating:please enter a value for the tax code after setting all the line items i am trying to set the taxcode as shown in code:currentRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'taxcode', value:salesOrd_taxcode[j], ignoreFieldChange: false, fireSlavingSync: true }); alert('taxcode is being set');
Two questions to ask then. 1. Are you setting the tax code as your final setValue? If not, one of the other setValues might be overwriting your value. 2. What value is salesOrd_taxcode[j] passing to the tax code field? Can you try setting that field with a hardcoded value to make sure it can work and then change it back to your code. Like this: currentRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'taxcode', value: 1, ignoreFieldChange: false, fireSlavingSync: true }); But change the 1 to a valid tax code in your account.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.