<@U29QCJQF3> That fail to me more than once, alway...
# suitescript
a
@michoel That fail to me more than once, always use:
runtime.getCurrentUser().getPreference({name: 'parameter_id'});
for Company level parameters.
s
wait a minute - you're saying we have to use getCurrent User in order to retrieve Company level parameters? How messed up is that?
a
@stalbert You can also use `N/config`: `config.load({ type: config.Type.COMPANY_PREFERENCES }).getValue({ fieldId: 'custscript_company_parameter' })`; But my point is:
runtime.getCurrentScript().getPreference()
failed to me many times when the script parameter has no value and the value is only set at the company level.
s
the observed behavior isn't surprising (for netsuite) but needing to invoke something about the user in order to get company level preferences is strange to me 🤷
a
Well it depends how you look at it, if you have a parameter ID which can have/store values in 3 places Script, General Preferences, User Preferences then the behavior of
getCurrentScript()
failing is kind of logical and if you open your mind User Preferences =
getCurrentUser()
and apparently the same applies for General Preference.
s
it does seem logical that getCurrentUser() would reveal user preferences.
d
@alien4u, may u can use
const myVar = config.load({ <code here> }) || {}
and see if this object until empty. This works to me when use MapReduce with or not params.
Like to use this way with optional parameters