I have a script written as SuiteScript 2.0 that is for beforeSubmit on sales orders. It runs perfectly fine when creating or updating a sales order using the UI. The script fails when creating or updating a sales order using webservices.
The error received is:
You do not have permissions to set a value for element subrecord_parent due to one of the following reasons: 1) The field is read-only; 2) An associated feature is disabled; 3) The field is available either when a record is created or updated, but not in both cases.
The script looks like:/** * * Purpose: Mark orders as service item only * * @version 1.0 * @NApiVersion 2.x * @NScriptName MarkOrderAsServiceOnly */ define(['N/record'], function(record) { function beforeSubmit(context) { var so = context.newRecord; var onlyService = true; var lineCount = so.getLineCount({sublistId: 'item'}); for (var x = 0; x < lineCount; x++) { var lineItem = so.getSublistValue({sublistId: 'item', fieldId: 'item', line: x}); debug('Item Number: ' + lineItem); if (lineItem != '723577') { onlyService = false; } } if (onlyService) { debug('Order contains only service items.'); so.setValue('custbody_only_service', true); } else { debug('Order DID NOT contain only service items.'); so.setValue('custbody_only_service', false); } } function debug(msg) { log.debug('debug', msg); } return { beforeSubmit: beforeSubmit }; });