Good morning, I am very new to suitescript, so any...
# suitescript
a
Good morning, I am very new to suitescript, so any guidance provided from the group would be greatly appreciated. I have run into a behavior when my user event script is run on the sales order. The code provided runs as expected when creating a new SO or editing an existing SO, but on approval of the SO it seems to be removing the "Drop Shipment" value(that is automatically set based on the checkbox from the item record) in the {createpo} line field and leaving the field blank("Drop Shipment" or "Special Order" is not populated)
Copy code
/**
 * @NApiVersion 2.0
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(['N/record'], function(record) {

    function beforeSubmit(context) {
		//Check if record's form is the Varsityline - Sales Order Form
		var formId = context.newRecord.getValue({ fieldId: 'customform' });
		if (formId === '204') {
			//Only run if SO is new or being edited
			if (context.type === context.UserEventType.CREATE || context.type === context.UserEventType.EDIT) {
				//Get SO number
				var newRecord = context.newRecord;
				//Get Vendor Name from povendor field on 1st line of sales order
				var firstVendor = newRecord.getSublistValue({
					sublistId: 'item',
					fieldId: 'povendor',
					line: 0
				});
				//Get line count
				var lineCount = newRecord.getLineCount({
					sublistId: 'item'
				});
				//Set povendor field on line items with the value from line 0 only if the checkbox is 'No'
				for (var i = 0; i < lineCount; i++) {
					var dontUseVendor = newRecord.getSublistValue({
						sublistId: 'item',
						fieldId: 'custcol_dont_use_vendor_on_all_lines',
						line: i
					});
					if (dontUseVendor === false) {
						newRecord.setSublistValue({
							sublistId: 'item',
							fieldId: 'povendor',
							line: i,
							value: firstVendor
						});
					}
				}
			}
		}
    }
    return {
        beforeSubmit: beforeSubmit
    };
});
k
@Aaron S is the value you are trying to edit check as a stored value?
a
The field that is being changed({povendor}) is a native field to NetSuite on the SO line level, so my assumption is that it is set to store the value. The field that is being updated by the approval of the SO({createpo}) is not in the script and should not be changing at all. This is unless it is a native bi-product of setting the {povendor} field. The weird thing is that the script works fine and sets all the lines on the SO to the same {povendor} and doesnt change the {createpo} field until approval of the SO.