hi everyone, I am trying to set boolean values on ...
# suitescript
k
hi everyone, I am trying to set boolean values on a custom column field associated to an item sublist in a sales order record. I am able to load the record and get any line item values, however when I am trying to set a value to the custom field, its not setting anything or throwing any error. My code that sets the sublist field value looks like this:
Copy code
soRec.setSublistValue({
     sublistId: 'item',
     fieldId: 'custcol_first_email',
     line: i,
     value: true
});
Is there something that I am missing?
m
Depending on the context of the script and how the field was created (e.g. scripted or not), I've intermittently had to use string
T
or
F
values instead of boolean `true`/`false`. Not sure if that's the issue here, but it's probably worth a shot at least. If that doesn't fix it, some more context within the script might help pinpoint the problem - what type of script, how you're loading
soRec
, etc.
k
hi @MTNathan , the field is created in UI. And I tried using
T
or
F
as well as
'T'
or
'F'
. `T`/`F` gave me a reference error, while nothing happened while wrapping those boolean value as a string. Regarding the script, its a map reduce script, and I am loading the
SoRec
like this:
Copy code
var soRec = record.load({
     type: record.Type.SALES_ORDER,
     id: so_id
});
n
are you saving the record after?
when I don't have something updating as I expect, I do the following logs - 1. check that my iterator is set to what I expect. 2. get the sublist value I'm manipulating before I set it. 3. Check the value I'm setting the sublist field to (N/A since this is hardcoded in your example) 4. get the sublist value I'm manipulating after I set it.
👍 2
9 times out of 10, I made a stupid mistake and this catches it 🙂
s
Line is actually a number, right, not the string
'0'
, this can cause problems. Also assuming didnt mistakenly start indexing at 1 instead of 0?
k
@Nicholas Klug I tried your recommendation, and initially I wasn't saving the record. Now when I am saving it, I am getting the following error:
{"type":"error.SuiteScriptError","name":"RCRD_HAS_BEEN_CHANGED","message":"Record has been changed","stack":["anonymous(N/serverRecordService)","reduce(/SuiteScripts/test.js:245)"],"cause":{"type":"internal error","code":"RCRD_HAS_BEEN_CHANGED","details":"Record has been changed","userEvent":null,"stackTrace":["anonymous(N/serverRecordService)","reduce(/SuiteScripts/testjs:245)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}
@Sandii I am actually looping through the existing line items and the loop does start its index with 0
n
What action is this script running on? If it's a user event, you very likely should be running this in the beforeSubmit
k
Its a Map Reduce
n
so, RCRD_HAS_BEEN_CHANGED means that another script or workflow has edited the record you've loaded between the time you loaded it and saved with your M/R script
this could be sheer coincidence or there's a collision between this and another script/workflow fighting with each other to make changes
k
there is a UE script thats running on the SO on
beforeSubmit
action, however, the two scripts have completely different logics running. I keep on getting the same after running the MR script again
n
have you checked the scripted record list on SO?
k
The values do however seem to have changed before setting it in the sublist and after setting it.
n
I'm not 100% on the location right now because I don't have access to an instance of NetSuite (new company, we're beginning implementation sometime soon), but I think it's customizations > records > scripted records, then go to sales order and see everything in the user event and workflow sublists
a beforeSubmit shouldn't produce that behavior
you need something that is saving the record before your script tries to save it
and since this is a map/reduce, we can very likely eliminate client scripts
k
there are 2 UE scripts, one runs only on beforeSubmit, and the other one runs on all 3 actions but does not seem to be saving the record
n
Are you saving the record after you've updated all of the sublist lines? Also, how are you determining which record to load and edit?
k
I am saving the record at the very end after all actions have been complete. Since its a MR script, I am feeding data via a saved search which determines which SO to load
n
If you load the saved search, do you have more than one line per Sales Order?
s
Yeah it sounds like the MR is loading the sames sales order more than once
and trying to save the same one multiple times
n
Yup. Your MR script might be fighting with itself 😂
k
no the saved search returns one line per SO
n
Well, unfortunately there's not much more insight I can give from here. This requires a lot of digging around to find a root cause for where the record contention is
k
I think I found the issue 🙂 So the reduce stage of my SO has a primary if-else condition, I was trying to load and save the SO record in each if-else condition (i know a very bad practice). I updated my code to load the SO before the if-else kicks in and save it after the if-else is done, and now it seems to be working as desired. Thank you guys for your help!
parrotbeer right 1
n
Nice! glad to hear it
🙂 1