Can I set a Value In UserEvent - Before Load funct...
# suitescript
n
Can I set a Value In UserEvent - Before Load function in Suitescript 2.0?
t
Yes @Netsuite    objRecord.setValue( { fieldId: 'item', value: true, ignoreFieldChange: true });
You have to pass js object to set value
n
var customerRecord = context.newRecord; customerRecord.setValue({ fieldId: 'custbody_test', value: 1, ignoreFieldChange: true })
I am passing like this but it is unable to set before load
are you there vikas?
n
According to NetSuite https://system.app.netsuite.com/app/help/helpcenter.nl?fid=section_4407991781.html
Data cannot be manipulated for records that are loaded in beforeLoad scripts. If you attempt to update a record loaded in beforeLoad, the logic is ignored.
Data can be manipulated for records created in beforeLoad user events.
t
See section 4387799721 there is an example they have done the same.
Also use logs to see where is the problem
n
can us send me the suite ans id please,unable to open that page
t
Replace the number in url given by ns_dev
n
@tuli Data can be manipulated for records created in beforeLoad user events. -> you can only update records which are created in beforeLoad. So if you look at the script example in section 4387799721(as you mentioned), beforeLoad method is not being executed if record is not in create mode.
@Netsuite, you should use pageInit from client-script to set any values on record, or you can create workflow and set values in it.
n
@ns_dev function beforeLoad(context) { if (context.type !== context.UserEventType.CREATE) return; var customerRecord = context.newRecord; customerRecord.setValue('phone', '555-555-5555'); if (!customerRecord.getValue('salesrep')) customerRecord.setValue('salesrep', 46); // replace '46' with one specific to your account }
In the help center they are using before load and they are setting the values for the record
n
but it returns from the method if context.type is not create
Copy code
if (context.type !== context.UserEventType.CREATE) return;
t
Yes he is right. You have to use pageinit of clientscript for doing this
Thanks @ns_dev
n
so..it is not possible in userevent right?
t
Yes
n
@tuli @ns_dev Thank you guys.