Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SuiteScript: before Submit (Set sublist Value using user event script)

I'm able to get values but not able to set sublist values in user event script beforeRecord submit. Looping through every line item to get the satisfying condition, when it come's to set value, I couldn't. am I passing wrong value or something? I'm not even receiving errors.

Please view script (edit):

if (context.type == context.UserEventType.EDIT) { var salesOrderRecord = context.oldRecord; var formId = salesOrderRecord.getValue({ fieldId: 'customform' }); if (formId == 150 ) { var recordId = salesOrderRecord.id; var lineCount = salesOrderRecord.getLineCount({ sublistId: 'item' }); for(var i = 0;i < lineCount; i++){ var sublistItemId = salesOrderRecord.getSublistValue({ sublistId: 'item', fieldId: 'item', line: i }); if (sublistItemId != '' && sublistItemId == 29498) { log.debug('Get Values',sublistItemId); salesOrderRecord.setSublistValue('item','location',i,39); } } }

like image 481
Harish Avatar asked May 31 '26 17:05

Harish


1 Answers

In a before submit function, context.oldRecord is a reference to the sales order before it was edited by the user. context.newRecord is a reference to the sales order after it was edited by the user but before it is committed to the database.

If you need to make changes, you should be updating context.newRecord as this will also include the changes to the record that the user just made and is the record that is going to be committed to the database.

like image 179
Mike Robbins Avatar answered Jun 03 '26 07:06

Mike Robbins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!