Good day! I'm using a user event script to load --...
# suitescript
r
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
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
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
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
Is there a difference? My version of this in 1.0 works smoothly when saving a record.
b
what does the code look like
r
are you referring to the 1.0 or in the 2.0?
b
both if you wanted me to compare them
r
@battk thank you for your help
b
your array indexes are pretty bad
r
yeah 😅 I'm planning to improve on that but I'm not having any errors from the arrays
b
do all your items have inventory details?
r
yes @battk
b
usually you have to use Record.hasSublistSubrecord to avoid creating subrecords
getting a subrecord will also create it in 2.0
r
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
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
Yes. But I will look into that as well
b
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
Thank you for your suggestions @battk
b
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
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