Here is the User Event Script
# suitescript
n
Here is the User Event Script
t
setting fields on before load is a bit of hit or miss. based on your code try a couple of things: 1- your record var for the record object is using the same name as the module callback. try changing this to currRecord or something as this may be causing a conflict 2- if 1 doesn't work can you set the data in a scripted field and access and set it on pageLoad?
n
I changed number one but that didn't work. Not sure I understand number 2
t
did you change this line as well if (record.type == 'customrecord_adb_eventlinup')
n
Yeah i did
No change. For the field I am trying to update, do I need to uncheck "store value"
c
Are you completely sure that custrecord_kes_adb_json_event_lineup is the id of the field?
t
if it sets it and you don't need to persist it to the database then that is similar to #2, which basically sets the data temporarily
n
I need it to update that field and then when I run a search I need to get that data so I can add it to another record type
c
I would avoid giving a variable the same name as a function parameter. In your case you are passing a param called record to the parent function and then declaring a variable called record within the beforeLoad function. I don't think it's causing you a problem yet but it won't help if later you want to use the parameter called record within beforeLoad
Please could you change lines 72 - 74 to as follows:
Copy code
var eventlineupjson = JSON.stringify(eventdetaildata);

log.debug({
    title: 'set custrecord_kes_adb_json_event_lineup to',
    details: eventlineupjson
});
            record.setValue({'fieldId':'custrecord_kes_adb_json_event_lineup', 'value': eventlineupjson});
Then make sure your logging level is set to Debug and run the script again and then look at the log
n
@cja got ya. Here is what the log returned.
Copy code
{
  "lineup": [
    {
      "artist": "",
      "host": "Blake Shelton - Host",
      "count": "2",
      "notes": "notes",
      "order": "1"
    }
  ]
}
But field was not set. Also, changed variable name
c
According to https://3640472-sb2.app.netsuite.com/app/help/helpcenter.nl?fid=section_4407991781.html&whence= "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."
Unrelated to your problem, in lines like the following, why do you enclose names in quotes?
n
Ahhh so how can I update the field dynamically? Whenever the record is created or edited, I need to grab the line items and populate the custom field. That is why I treid before load
c
Copy code
record.setValue({'fieldId':'custrecord_kes_adb_json_event_lineup', 'value': eventlineupjson});
So why is fieldId in quotes?
and value
I don't think it matters as far as the effectiveness of your code, but it reads better without quotes
I'm not a JavaScript expert so wondering if there's a reason
n
not necessarily a reason honestly. I tend to do both sometimes.
c
"how can I update the field dynamically" - could you do it when the record is saved?
n
I tried moving the code to an after submit but it didn't update that field
c
It would make most sense in after submit. It should be possible. Rewrite the code for after submit, test again and if you can't get it to work then paste here
n
So I put a single log statement in the afterSubmit and it didn't even log that after I saved.
never mind. I got that working. But still not setting that field.
GOT IT! For some reason it didn't like the afterSubmit, but it worked perfect on beforeSubmit
c
Rethinking what I said earlier, before submit is most efficient because it avoids having to save the record one more time to do your update
So I reckon you have the best solution now