I posted last week about a script issue I was havi...
# suitescript
t
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 }; });
b
the line count of a new record is 0
and your code only runs once, at pageInit, not that running it more would help with the first line
you should be using Column.isDisabled instead
expect to disable columns in more than just the pageInit, netsuite will undisable the columns it uses for sourcing
e
In a past thread @battk explained this to me. I added the instruction both on
pageInit
and
postSourcing
and it worked perfectly for the column
amount
. Thanks again!
t
@Edgar Valdes I am very green at this, I am not sure I am following you, are you saying you have section for pageInit and postSourcing instead of 1 section for just pageinit?
e
Two different entry points in the script
b
let him fix the first problem first, then move onto the second
t
If I only knew how to fix the first problem I would, I am brand new to scripts. I am asking for a little patience and guidance, instead of sarcasim! I used ChatGPT to get the foundation. Is there anyone out there that would be willing to just help me get this script to work on both edit and create?
b
first off you want to identify why your code isnt working
in this case, you were told upfront what that was, your transaction doesnt have any lines when its first created
so the line count is 0
what happens in your for loop when the line count is 0
t
Well since it does not disable the columns, I am assuming nothing, but that is the problem that I do not know how to fix, I am assuming I have to change something in the first line of the "For" loop, but I do not know what. for (var i = 0; i < lineCount; i++)
b
you probably want to understand this better than assuming what the problem is, you need to be able to identify which part here isnt working for your scenario
you want to understand what a for loop does, especially what the condition does