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!!
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.
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!
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