The following script sets the tax code field to blank under certain roles. It also does not log the value of the tax code field in the console log.
/** * @NApiVersion 2.x * @NScriptType ClientScript */
// Define the dependencies required for the client scriptdefine(["N/currentRecord"], function (currentRecord) { // Function triggered when a field is changed function fieldChanged(context) { var currentRecordObj = currentRecord.get(); var sublistName = context.sublistId; var fieldName = context.fieldId; // Check if the sublist is the expense sublist and the field changed is the custom operations category if (sublistName === "expense" && fieldName === "custcol_ops_accounts") { console.log('field changed',fieldName) // Get the custom operations category value from the sublist line var operationsAccount = currentRecordObj.getCurrentSublistValue({ sublistId: "expense", fieldId: "custcol_ops_accounts", }); console.log('operationsAccount',operationsAccount) // Get the native expense category value from the sublist line var account = currentRecordObj.getCurrentSublistValue({ sublistId: "expense", fieldId: "account", }); // Log these values to the script execution log log.debug("Field Changed - Operations Account", operationsAccount); log.debug("Field Changed - Account", account); // If the native expense category at a line level is blank, set it to the custom operations category value if (operationsAccount) { currentRecordObj.setCurrentSublistValue({ sublistId: "expense", fieldId: "account", value: operationsAccount, ignoreFieldChange: true, }); log.debug("Set account field value", operationsAccount); } } } function lineInit(context) { var currentRecord = context.currentRecord; var sublistId = context.sublistId; if (sublistId === 'item') { disableFields(currentRecord, sublistId, ['amount', 'quantity', 'rate', 'taxcode']); } if (sublistId === 'expense') { disableFields(currentRecord, sublistId, ['amount', 'grossamt','taxcode', 'tax1amt']); } } function validateLine(context) { var currentRecord = context.currentRecord; var sublistId = context.sublistId; if (sublistId === 'item') { disableFields(currentRecord, sublistId, ['amount', 'quantity', 'rate', 'taxcode']); } if (sublistId === 'expense') { disableFields(currentRecord, sublistId, ['amount', 'grossamt', 'taxcode', 'tax1amt']); } return true; // Return true to allow the line to be saved } function disableFields(currentRecord, sublistId, fieldIds) { fieldIds.forEach(function (fieldId) { var field = currentRecord.getCurrentSublistField({ sublistId: sublistId, fieldId: fieldId }); if (field) { field.isDisabled = true; } }); } return { lineInit: lineInit, fieldChanged: fieldChanged, validateLine: validateLine }; });
It does that for non admin roles.
Under the admin role, the script does not wipe out the contents of the tax code field.
Why would a role permission cause the difference in behaviour?