https://netsuiteprofessionals.com logo
r

Rywin

04/28/2022, 8:15 AM
Good day! I'm using a user event script to load ---> set values ---> save the record and there are times I am getting an UNEXPECTED_ERROR. Sometimes the script works sometimes it goes to this error. Any suggestions? Thank you!
b

battk

04/28/2022, 8:16 AM
hopefully your unexpected error has a code that you can give to netsuite support so they can help you out
otherwise you need to figure out what inputs are needed to reproduce the problem
r

Rywin

04/28/2022, 8:18 AM
this is a sample of the error @battk The line in my script refers to the record.save();
Copy code
{
  "type": "error.SuiteScriptError",
  "name": "UNEXPECTED_ERROR",
  "message": "An unexpected SuiteScript error has occurred",
  "stack": [
    "Error\n at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js:371:13)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js:115:24)\n at Object.beforeSubmit (/SuiteScripts/cfs_Itemfulfillment_ue.js:375:29)"
  ],
  "cause": {
    "type": "internal error",
    "code": "UNEXPECTED_ERROR",
    "details": "An unexpected SuiteScript error has occurred",
    "userEvent": null,
    "stackTrace": [
      "Error\n at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js:371:13)\n at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js:115:24)\n at Object.beforeSubmit (/SuiteScripts/cfs_Itemfulfillment_ue.js:375:29)"
    ],
    "notifyOff": false
  },
  "id": "",
  "notifyOff": false,
  "userFacing": true
}
b

battk

04/28/2022, 8:20 AM
its usually not a good sign that you are loading and saving a record in before submit
before submit happens before the record is actually saved to the database, there is still room for the save to fail
r

Rywin

04/28/2022, 8:21 AM
Is there a difference? My version of this in 1.0 works smoothly when saving a record.
b

battk

04/28/2022, 8:24 AM
what does the code look like
r

Rywin

04/28/2022, 8:25 AM
are you referring to the 1.0 or in the 2.0?
b

battk

04/28/2022, 8:27 AM
both if you wanted me to compare them
r

Rywin

04/28/2022, 8:33 AM
@battk thank you for your help
b

battk

04/28/2022, 8:40 AM
your array indexes are pretty bad
r

Rywin

04/28/2022, 8:42 AM
yeah 😅 I'm planning to improve on that but I'm not having any errors from the arrays
b

battk

04/28/2022, 8:43 AM
do all your items have inventory details?
r

Rywin

04/28/2022, 8:44 AM
yes @battk
b

battk

04/28/2022, 8:44 AM
usually you have to use Record.hasSublistSubrecord to avoid creating subrecords
getting a subrecord will also create it in 2.0
r

Rywin

04/28/2022, 8:45 AM
All of our items that has fulfillment are all Lot-Numbered Inventory Items
I can also add that in case we will have a different Item Type
b

battk

04/28/2022, 8:58 AM
Copy code
var TranFields = search.lookupFields({
  type: search.Type.TRANSACTION,
  id: idSO,
  columns: ["type", "intercotransaction"],
});
try {
  var TranType = TranFields["type"][0].value;
  var IntercoTran = TranFields["intercotransaction"][0].value;
} catch (e) {
  log.debug("TranFields Before Submit", JSON.stringify(e));
}
doesnt look right
intercotransaction
shouldnt be an array
though i dont think that would cause your error
r

Rywin

04/28/2022, 8:59 AM
Yes. But I will look into that as well
b

battk

04/28/2022, 9:20 AM
you need to be more consistent with your use of your checks on
committed !== '0'
its not always present
and i dont think its actually translated correctly, the quantitycommitted should be a number
you probably want to copy
Copy code
nlapiSubmitField('lotnumberedinventoryitem',SOItemID,salesrep_itemfld_map[Team].qs,NewQS);
as is
the old code is not thread safe and will be wrong for concurrency
your new code wont be wrong, but will throw errors
you also dont want to use dynamic mode for record2
suitescript 1 version doesnt
it matters since you are reassigning the lots (in a really weird way)
r

Rywin

04/28/2022, 10:03 AM
Thank you for your suggestions @battk
b

battk

04/28/2022, 10:05 AM
id tell you to do this aftersubmit, you probably dont want any of the logic to run if the item fulfillment fails to save after the before submit
im not really sure if you could, your lot assignment is weird, and might not actually work if the item fulfillment is saved\
general performance wise, dont use search.lookupFields in a loop
get all the ids you want to lookup first, then do a search to get them all at once
honestly, im not surprised that you are getting unexpected errors
you really dont want to modify the sales order while the fulfillment is being created
r

Rywin

04/28/2022, 10:09 AM
Thank you @battk for your recommendations for best practices. I learned 1.0 just on my own. Before it doesn't matter for me how the script was created as long as it works and I should consider these moving forward in 2.0