User Event on Sales Order to get Item record (Sublist) Details.
Category : SuiteScript 2.0
In this tutorial of netsuite solution provider you will learn netsuite customization.
Script to get Values of Sales Order and load the Item to get sublist value of Item Record.
As a netsuite solution provider we are giving you Use Case: In this example we are going to write a user event script which will be deployed on Sales order and getting the field values of Sales order and line items values of sales order. After storing the item ids in a variable the script is loading the items to get the Item vendor details from the item record. This example can be utilized in you netsuite implementation.
In this example we are loading a child record and exploring the sublist of child record.
Api Covered : record.load, getValue for body field, getLineCount for line items, getSublistValue
SALES ORDER =>get ITEM (sublist) => Load ITEM => get ITEM Sublist (Vendor) details
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
define([‘N/record’], function (record) {
function beforeLoad(context) {
}
function beforeSubmit(context) {
var recid = context.oldRecord.id
log.debug(‘orderid’, recid)
var SOobj = record.load({
type: record.Type.SALES_ORDER,
id: recid,
})
//load the SO and get the trandate and store in a variable oderdate
var oderdate = SOobj.getValue({
fieldId: ‘trandate’})
log.debug(oderdate);
//get the number of line in SO: numLines
var numLines = SOobj.getLineCount({
sublistId: ‘item’
});
log.debug({
title: ‘numLines’,
details: numLines
})
//loop through the number of line in SO
for (var i = 0; i < numLines; i++) {
//get the internalid of the item
var internalid_item = SOobj.getSublistValue({
sublistId: ‘item’,
fieldId: ‘item’,
line: i
});
log.debug({
title: ‘linedetails’,
details: ‘line number ‘ + i + ‘is having ‘ + internalid_item
})
//load the item using the internal id
var itemObj = record.load({
type: record.Type.LOT_NUMBERED_INVENTORY_ITEM,
id: internalid_item,
})
log.debug(‘itemObj’, itemObj)
//check the field dropship item value from item record
var checkbo = itemObj.getValue({
fieldId: ‘isdropshipitem’
})
if (checkbo) {
//logic if the dropdhip check box is true we come inside the loop
log.debug(‘insideif’, ‘yes the item is derop ship’) // then get the sublist value of vendor in Item record
var valoue_v =itemObj.getSublistValue({
sublistId:’itemvendor’,
fieldId:’vendor’ ,
line: i
})
log.debug({
title: ‘valoue_v’,
details: valoue_v
})
}
}
}
function afterSubmit(context) {
}
return {
beforeLoad: beforeLoad,
beforeSubmit: beforeSubmit,
afterSubmit: afterSubmit
}
});
Feel free to reach out Netsuite Solution provider TheSmilingCoders for proper netsuite implementation, netsuite consultation , netsuite customization, netsuite Support, netsuite Training , NetSuite Celigo Integration , Celigo Consultant, Celigo Integration Consultant.
contact us : [email protected]
Linkedin : https://www.linkedin.com/company/netsuite-academy/