Reputation: 47
I want to transform sales order to item fulfillment with inventory details. I found a sample on suiteanswers. But I am unsure about how to access values like issueinventorynumber, binnumber, quantity to set on inventory details record. In the sample code they have hardcoded these values. I will appreciate your help.
var ifRec = nlapiTransformRecord('salesorder', , 'itemfulfillment');
ifRec.selectLineItem('item', 1);
ifRec.setCurrentLineItemValue('item', 'location', 1);
var ifDetail = ifRec.createCurrentLineItemSubrecord('item', 'inventorydetail');
ifDetail.selectNewLineItem('inventoryassignment');
ifDetail.setCurrentLineItemValue('inventoryassignment', 'issueinventorynumber', 25);
//lot number's Internal ID
ifDetail.setCurrentLineItemValue('inventoryassignment', 'binnumber', 1); //bin
number's Internal ID
ifDetail.setCurrentLineItemValue('inventoryassignment', 'quantity', 1);
ifDetail.commitLineItem('inventoryassignment');
ifDetail.commit();
ifRec.commitLineItem('item');
var ifID = nlapiSubmitRecord(ifRec);
Upvotes: 0
Views: 1109
Reputation: 26
To transform Sales Order into Item Fulfillment:
var objItemFulfillment = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: salesOrderID,
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: false
});
Inventory Details are its own subrecords which may exist on each line. When you are looping through the lines of your transformed Item Fulfillment, you can get the Inventory Details subrecord. If it doesn't exist, it will create one, otherwise you will be editing the existing one.
The fieldId
for inventory details subrecord is inventorydetail
.
let intIFLineCount = objItemFulfillment.getLineCount({sublistId: 'item'});
for (let i = 0; i < intIFLineCount; i++)
{
//this is your inventory details record
let objSubrecord = objRecord.getSublistSubrecord({
sublistId: 'item',
fieldId: 'inventorydetail',
line: i
});
}
Inventory Details is a record like any other, with its own sublist inventoryassignment
which contains various fields, which you can find here:
https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2023_2/script/record/inventorydetail.html
Into this sublist you can set values like you normally would:
objSubrecord.setSublistValue({sublistId: 'inventoryassignment', fieldId: 'binnumber', value: 123456, line: x});
objSubrecord.setSublistValue({sublistId: 'inventoryassignment', fieldId: 'quantity', value: 20, line: x});
You can of course retrieve the values from existing inventory details too:
let binNumber = objSubrecord.getSublistValue({sublistId: 'inventoryassignment', fieldId: 'binnumber', line: x});
let quantity = objSubrecord.getSublistValue({sublistId: 'inventoryassignment', fieldId: 'quantity', line: x});
So the only annoying part is that you will be looping through the item sublist on the Item Fulfillment record, and on each line you will loop through another sublist, this time for the Inventory Details record.
Upvotes: 0
Reputation: 187
That code is using SuiteScript 1, I'd strongly advise you to use SuiteScript 2. (you can recognize SS1 because of functions named with "nlapi...".
I don't have access to a Netsuite account to test it, but got this example from Netty.ai:
var salesOrderID = '123'; // Replace with the actual sales order ID
// Create a dynamic item fulfillment request record
var fulfillmentRequestRecord = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: salesOrderID,
toType: record.Type.FULFILLMENT_REQUEST,
isDynamic: true
});
var fulfillmentRequestLinesCount = fulfillmentRequestRecord.getLineCount({
sublistId: 'item'
});
// Loop through each line item in the fulfillment request
for (var line = 0; line < fulfillmentRequestLinesCount; line++) {
var issueInventoryNumber = fulfillmentRequestRecord.getSublistValue({
sublistId: 'item',
fieldId: 'issueinventorynumber',
line: line
});
var binNumber = fulfillmentRequestRecord.getSublistValue({
sublistId: 'item',
fieldId: 'binnumber',
line: line
});
var quantity = fulfillmentRequestRecord.getSublistValue({
sublistId: 'item',
fieldId: 'quantity',
line: line
});
// Set the values on the inventory details record
// ...
// Save the fulfillment request record
// ...
}
Upvotes: 0