got a restlet script for creating item fulfilments...
# suitescript
g
got a restlet script for creating item fulfilments based on incoming array and transform from sales order: this is what the array looks like:
'[
{
"salesOrderExternalId": "082372348",
"status": "C",
"salesOrderId": "2342347",
"linesToFulfill": [
{
"line": 1,
"quantity": 1
},
{
"line": 2,
"quantity": 1
},
]
},
{
"salesOrderExternalId": "123123123",
"status": "C",
"salesOrderId": "42334",
"linesToFulfill": [
{
"line": 1,
"quantity": 3
},
"line": 16,
"quantity": 1
},
]
}
]'
This below script works if I exclude line 16 from the array but I need it work for this, I've checked the line from the sales order and it is one that can fulfil so not sure what the issue is:
{
"line": 16,
"quantity": 1
},
b
not enough description given, we dont know how it fails, what error code or message
g
sorry thought I added the error message: so the first array works 77654529: second one with line 16 gives error message:
{"type":"error.SuiteScriptError","name":"SSS_INVALID_SUBLIST_OPERATION","message":"You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.","id":"","stack":["anonymous(N/serverRecordService)","doPost(/SuiteScripts/ABC.js:67)"],"cause":{"type":"internal error","code":"SSS_INVALID_SUBLIST_OPERATION","details":"You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.","userEvent":null,"stackTrace":["anonymous(N/serverRecordService)","doPost(/SuiteScripts/ABC.js:67)"],"notifyOff":false},"notifyOff":false,"userFacing":false}
b
thats the error you get when you do something invalid on a sublist
since its happening on line 67, that suggests that the fulfillment doesnt have that line to select
can usually confirm by checking what line you are trying to select and then comparing it to the fulfillments line's
in general the way your code is written doesnt work when the order is fulfilled partially, either by line or by quantity
g
and the complication when transforming the SO to IF is the numbering is different because I think usually IF's go like 0,3,6 whilst the SO line numbering starts at 1, 2 and then if you add/remove lines, it jumps to additional numbers etc..
b
you are using the line on the sales order to select the line on the item fulfillment
that only works in the most basic of use cases
you need to use the line from the sales order to match to the orderline on the fulfillment
and keep in mind that line field/column refers to the line id, which is not the same as the line sequence number
all the line related methods in suitescript 2 use line to refer to the line index, which is neither the line id nor the line sequence number
though the line index is related to the line sequence number, being offset by 1 like array indexes