Requirement: Our Client required to generate IF as shipped status when a wave is released and picked. As per NetSuite standard functionality, the WMS created IF has picked status. So, we need to customize the standard functionality by using Restlet script and User event script.
First, we need to clone the existing Multi-order picking and create a custom field in the last page (Enter Staging) and set a default value in that field.
We need to add the restlet script on the after submit ONCLICK action of “Enter staging” button.
Restlet script
/**
* @NApiVersion 2.1
* @NScriptType Restlet
*/
define(['N/record','N/search'],
(record,search) => {
const post = (requestBody) => {
try {
log.debug("requestbody", requestBody);
var test = requestBody;
// get the object from the WMS restlet action
log.debug('test.params.impactedRecords.salesorder[0]', test.params.impactedRecords.salesorder);
var soidArr = test.params.impactedRecords.salesorder
var wmsValue = test.params.recordsData.salesorder.standardFields.custbody_if_created_wms
for(i=0; i<soidArr.length; i++) {
// var resultObj = salesorderSearchfn(soid);
//
// log.debug('resultObj', resultObj);
var soId = record.submitFields({
type: record.Type.SALES_ORDER,
id: soidArr[i],
values: {
custbody_if_created_wms: wmsValue
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
log.debug("wmsValue", wmsValue);
}
}
catch (e) {
log.error('error@post', e);
}
}
return {post}
});
We will set the custom field value in the sales order record. A user event script deployed in the IF to set the status as shipped.
User Event Script
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/record','N/search'],
(record, search) => {
/**
* Defines the function definition that is executed after record is submitted.
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
* @since 2015.2
*/
const afterSubmit = (scriptContext) => {
try {
log.debug("inside WMS aftersubmit", true);
var rec = scriptContext.newRecord;
log.debug("recobj", rec.id);
var createdfrom = rec.getValue({
fieldId: 'createdfrom'
})
log.debug("createdfrom", createdfrom);
var type = search.lookupFields({
type: search.Type.TRANSACTION,
id: createdfrom,
columns: ["custbody_if_created_wms"]
});
log.debug("type WMS field", type);
var wmsValue = type.custbody_if_created_wms;
log.debug("wmsValue field", wmsValue);
if (wmsValue == 'WMS') {
var ifRec = record.load({
type: record.Type.ITEM_FULFILLMENT,
id: rec.id,
isDynamic: true
});
ifRec.setValue({
fieldId: 'shipstatus',
value: 'C'
})
var recID = ifRec.save();
log.debug("recID", recID);
}
}
catch (e){
log.debug("error@aftersubmit", e);
}
}
return {afterSubmit}
});