I posted last week about a script issue I was having, turns out it was the script Type, needed to be a client script, instead of a user event. So I got the script to run, but it only disables the columns when the user goes in and edits the sales order, not when they create a new one. I know the script is running. Anyone know why this script runs, but only disables the columns when they edit an existing Sales Order and not when they create a new one?
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord', 'N/runtime'], function(currentRecord, runtime) {
function pageInit(context) {
var currentUser = runtime.getCurrentUser();
var userRoleId = currentUser.role;
// Display a message indicating the role of the logged-in user
alert('You are logged in as a user with the role: ' + userRoleId);
var mode = context.mode;
// Check if the script is running in create or edit mode
if (mode == 'create' || mode == 'edit') {
// Check if the user has the specific role
if (userRoleId == '1127') {
var currentRecordObj = currentRecord.get();
var lineCount = currentRecordObj.getLineCount({
sublistId: 'item'
});
// List of column IDs to disable
var columnsToDisable = ['description', 'price', 'rate']; // Add more column IDs as needed
for (var i = 0; i < lineCount; i++) {
// Disable specific columns on each line item
columnsToDisable.forEach(function(columnId) {
currentRecordObj.getSublistField({
sublistId: 'item',
fieldId: columnId,
line: i
}).isDisabled = true; // Set to true to disable the field
});
}
// Display role information
alert('You are logged in as a user with the specified role.');
} else {
// Display message if the user does not have the specified role
alert('You are logged in as a user without the specified role.');
}
}
}
return {
pageInit: pageInit
};
});