Hi there, bit of a tricky one perhaps.
In my script, one of the functions I have is used to update fixed asset records if an item receipt has its landed cost added.
In the first script example, the script works but gets overloaded if there are too many items on the IR as it runs a search for each serialized item, quickly eating up all the credit allowance or whatever it is I'm allowed for running a script.
So in my second example, I'm trying to add each of the serial numbers into a single search before running it, so that I perform far fewer searches for the asset records I need to update.
The error is occurring at the line "var assetResults = assetSearch.run().getRange({ start: 0, end: 100 });" where the search is being run.
However, this is met with the error:
{"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"id":"76f57c81-d668-489d-bfa1-43d30f986b95-2d323032342e30382e3035","stack":["getRange(N/searchObject)","handleLandedCost(/SuiteScripts/CreateAsset.js:234)","afterSubmit(/SuiteScripts/CreateAsset.js:87)"],"cause":{"type":"internal error","code":"UNEXPECTED_ERROR","details":null,"userEvent":"aftersubmit","stackTrace":["getRange(N/searchObject)","handleLandedCost(/SuiteScripts/CreateAsset.js:234)","afterSubmit(/SuiteScripts/CreateAsset.js:87)"],"notifyOff":false},"notifyOff":false,"userFacing":false}; ID: lzh6347e1jh2palivnlx1
I'm very uncertain how to debug this. As far as I can tell, the array is being filled correctly and then it's something to do with the getRange function? I tried removing that but then the forEach function doesn't work without it.
I only managed to find this stackoverflow thread but wasn't sure if it applies to my case or not.
If anyone has some clue as to what's going wrong, I'd be very grateful to hear it.