How can a variable be stored and accessed as read ...
# ask-stanley-ai
l
How can a variable be stored and accessed as read only that contains a list of user defined record ids? Eg:
Copy code
// someMainScript.js
function (someParam) {
  const multiplier = runtime.getSystemParam('multiplier')
  doAmazingThing(someParam, multiplier)
}
c
AI generated answer (using internal Slack threads):
To store a variable as read-only that contains a list of user-defined record ids, you can use a combination of SuiteScript and Script Parameters. First, you would define a company script parameter in your script. This parameter can be accessed by all scripts through the N/config module. Here is an example of how you can define a company script parameter:
Copy code
javascript
var rec = record.load({type: 'scriptdeployment', id: 1234});
rec.getValue('custscript_your_param');
You can also load the script and get all parameter ids:
Copy code
javascript
let allParameterIds = [];
let thisScript = record.load({
    type: record.Type.SUITELET,
    id: [YOUR SCRIPT ID]
});
let parameterCount = thisScript.getLineCount({
    sublistId: 'parameters'
});
for (i = 0; i < parameterCount; i++) { 
    let currentParameterId = thisScript.getSublistValue({
        sublistId: 'parameters',
        fieldId: 'internalid',
        line: i
    });
    allParameterIds.push(currentParameterId);
}
To make the script parameter read-only, you can uncheck the 'store value' checkbox while creating the script parameter. This way, only the script can update the parameter dynamically. Alternatively, you can change the default access level to 'View' under the access tab. Remember, if you want to ensure that the settings are not accidentally assigned, you can add
as const
to the end of the return statement object if you are using TypeScript. This is a compile-time check and you would know if you made a mistake before you even upload the code. If you are using JavaScript, you can use
Object.freeze
to make the object immutable. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.827885151
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.821983814
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.819605649
Please provide your feedback on this answer.