Good day! I'm using a user event script to load --...
# suitescript
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!
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
this is a sample of the error @battk The line in my script refers to the;
Copy code
  "type": "error.SuiteScriptError",
  "message": "An unexpected SuiteScript error has occurred",
  "stack": [
    "Error\n at (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 (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
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
Is there a difference? My version of this in 1.0 works smoothly when saving a record.
what does the code look like
are you referring to the 1.0 or in the 2.0?
both if you wanted me to compare them
@battk thank you for your help
your array indexes are pretty bad
yeah 😅 I'm planning to improve on that but I'm not having any errors from the arrays
do all your items have inventory details?
yes @battk
usually you have to use Record.hasSublistSubrecord to avoid creating subrecords
getting a subrecord will also create it in 2.0
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
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
shouldnt be an array
though i dont think that would cause your error
Yes. But I will look into that as well
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
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)
Thank you for your suggestions @battk
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
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