RE: In SS2.x, can you set a field value in beforeLoad of a User Event script?

Hello!

 

So in a User Event script in the beforeLoad function I need to set a custom Transaction Body Field value, like this:


var newRecord = context.newRecord;

newRecord.setValue({

fieldId: 'custbody_my_custom_field',

value: true // or false

});

Logging the result of the above, I can see the value change, but it does not persist through the entire page load, and always returns to the default state. I have ‘Store Value’ checked on the field’s setup. So, is it just not possible to set a field value in beforeLoad and have that value persist?

 

Thanks for any help!!

 

mreser Rookie Asked on September 16, 2019 in SuiteScript.

Hi,

SuiteScript 2.X allows you to set field values on before load in user event scripts. If this behavior is not happening, then there must be some other script interfering, load time errors which can be checked with debugger, or a browser issue. You can update field values that are blank, or just mimic this logic on the beforesubmit trigger.

on February 5, 2025.
Add Comment
4 Answers

Hi, are you sure there’s no other user event or workflow or client script re-setting the variable after you set it on the first place? I tried this:

/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* UserEventScript
*/
define([],
function a() {
'use strict';
return {
beforeLoad: beforeLoad
};
function beforeLoad(context) {
context.newRecord.setValue({
fieldId: 'custbody_sample',
value: true,
ignoreFieldChange: true
});
}
}
);

It works, the field is set to true when the sales order finished loading.

Beginner Answered on September 16, 2019.

Thanks! Yes, I am sure. The field I am attempting to set is a new custom field, not referenced anywhere else. It’s good to know you got the above to work and the only thing I see right off is the `ignoreFieldChange` property. I am pretty new to SS and need to look that up in the documentation; I am not including that, so maybe it is as simple as that!

on September 16, 2019.

So I added the ignoreFieldChange property, and this is definitely not setting the value, or rather, the logging shows the same as it has: It sets the value, but then it doesn’t persist and it goes back to its original value. So weird. Wish I knew what was going on

on September 16, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.