NetSuite Rest转换销售订单创建含批次号ItemFulfillment问题排查
我有一个.Net应用,通过以下NetSuite REST API URL从salesOrder创建itemFulfillment并更新发货信息:
https://{{COMPANY_URL}}/services/rest/record/v1/salesorder/{{SOID}}/!transform/itemFulfillment
初始请求体:
{ "item": { "items": [ { "orderLine": 1, "location": 16, "quantity": 2, "itemReceive": true }, { "orderLine": 2, "location": 16, "itemReceive": false } ] } }
处理**批次控制(Lot Controlled)**物料时触发报错:
Error while accessing a resource. Please configure the inventory detail in line 1 of the item list
修改请求体加入inventoryDetail后:
{ "item": { "items": [ { "orderLine": 1, "location": 16, "quantity": 2, "custcol_wayb_serial_number": "PI-NN001503", "inventoryDetail": { "inventoryAssignment": { "items": [ { "issueInventoryNumber": "22CWB08-2", "quantity": 2 } ] } } }, { "orderLine": 2, "location": 16, "itemReceive": false } ] } }
仍报错:
Error while accessing a resource. You have entered an Invalid Field Value 22CWB08-2 for the following field: issueinventorynumber
已知可能需要传入inventoryNumber的ID,但仅持有批次号文本;查询inventoryNumber时,物料多位置存在会返回多条记录,且无法直接按位置筛选。
我的问题:
- 如何修改代码解决创建itemFulfillment的问题?
- 若需inventoryNumber的ID,如何通过批次号和位置查询获取?
目前正在PostMan中做原型验证,验证通过后将用.Net实现。
1. 修正itemFulfillment创建请求
报错核心是issueInventoryNumber字段需要传入inventoryNumber的内部ID,而非批次号文本。同时要确保inventoryDetail的结构符合NetSuite API要求,调整后的请求体示例:
{ "item": { "items": [ { "orderLine": 1, "location": 16, "quantity": 2, "custcol_wayb_serial_number": "PI-NN001503", "itemReceive": true, "inventoryDetail": { "inventoryAssignment": { "items": [ { "issueInventoryNumber": 12345, // 替换为inventoryNumber的内部ID "quantity": 2, "location": 16 // 显式指定位置,避免歧义 } ] } } }, { "orderLine": 2, "location": 16, "itemReceive": false } ] } }
关键注意点:
- 批次控制物料的发货行必须添加
inventoryDetail节点,且issueInventoryNumber必须使用内部ID而非文本批次号 - 在inventoryAssignment中显式声明
location,确保系统匹配对应位置的库存批次
2. 通过批次号+位置查询inventoryNumber内部ID
使用NetSuite的REST API查询inventorynumber记录,通过批次号、位置ID、物料ID组合筛选,精准定位目标批次:
查询URL
https://{{COMPANY_URL}}/services/rest/record/v1/inventorynumber?ql=SELECT id FROM inventorynumber WHERE inventorynumber = '22CWB08-2' AND location = 16 AND item = {ITEM_INTERNAL_ID}
参数说明
inventorynumber = '22CWB08-2':匹配目标批次号文本location = 16:指定库存所在位置IDitem = {ITEM_INTERNAL_ID}:关联销售订单行对应的物料内部ID,进一步缩小范围
.Net实现步骤
- 从销售订单的行项目中提取对应物料的内部ID
- 构造上述QL查询请求,发送到NetSuite REST API
- 解析返回的JSON结果,提取目标inventorynumber的
id字段 - 将该ID填入itemFulfillment请求体的
issueInventoryNumber字段
额外优化
- 如果查询返回多条记录,可添加
quantityavailable > 0条件,筛选有可用库存的批次 - 确保应用的NetSuite API权限包含
inventorynumber记录的查询权限
内容的提问来源于stack exchange,提问作者Thomas A. Johnson

