Jira Code: CCHI-6 SO Record
- Created line item fields in Sales Order
If values in “ARRIVING WITHIN 31-60 DAYS”,” ARRIVING WITHIN 61-90 DAYS”,” ARRIVING WITHIN 90-120 DAYS” of item record greater than 0 a UserEvent Script runs, get the quantity and the field id. If a value greater than 0 set that field value in “Arriving Quantity” of type Free form text field and the list value in “Next Shipment ETA” respectively in the corresponding Sales Order. If there are no values in any of the fields: ARRIVING WITHIN 31-60 DAYS”,” ARRIVING WITHIN 61-90 DAYS”,” ARRIVING WITHIN 90-120 DAYS then Next Shipment ETA is set to “120+ days” and the quantity will be 0.
2. Created Custom list field with values 31-60 days, 61-90 days ,91-120 days and 120+ days.
- Next Shipment ETA
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/**
* Script Description
* Script get the values of Inventory stock details from Fields Next Shipment ETA and Arriving Quantity
from Item and update it in sales order.
**/
/*******************************************************************************
* CCHI
* **************************************************************************
*
* Date: 19-03-2019
*
* Author: Jobin & Jismi IT Services LLP
*
*
* REVISION HISTORY
*
* Revision 1 $ 19-03-2019 rijoy : Created
*
*****************************************************************************
**/
define(['N/file', 'N/record', 'N/runtime', 'N/search'],
/**
* @param {file} file
* @param {record} record
* @param {runtime} runtime
* @param {search} search
*/
function(file, record, runtime, search) {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type
* @param {Form} scriptContext.form - Current form
* @Since 2015.2
*/
/*function beforeLoad(scriptContext) {
}*/
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type
* @Since 2015.2
*/
/*function beforeSubmit(scriptContext) {
}*/
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type
* @Since 2015.2
*/
function afterSubmit(scriptContext) {
try{
var count_31days;
var count_61days;
var count_91days;
/*log.debug("scriptContext.type",scriptContext.type);*/
var cust_form = scriptContext.newRecord.getValue({
fieldId : 'customform'
});
if((scriptContext.type== "create"||scriptContext.type== "edit")&&(cust_form=="129"||cust_form=="104")){
var recId = scriptContext.newRecord.id;
var N_lines = scriptContext.newRecord.getLineCount({
sublistId : 'item'
});
for (var i = 0; i < N_lines; i++) {
var Item=(scriptContext.newRecord.getSublistValue({
sublistId : 'item',
fieldId : 'item',
line : i
}));
var item_Deatils= search.create({
type: "item",
filters:
[
["internalid","anyof",Item]
],
columns:
[
search.createColumn({
name: "custitem_available_31_days",
}),
search.createColumn({
name: "custitem_available_61_days",
}),
search.createColumn({
name: "custitem_available_91",
}),
]
});
item_Deatils.run().each(function(result) {
count_31days = result
.getValue(item_Deatils.columns[0]);
count_61days = result
.getValue(item_Deatils.columns[1]);
count_91days = result
.getValue(item_Deatils.columns[2]);
});
if(count_31days>0){
update_SO(count_31days,"31-60 days",recId,i);
}
else if(count_61days>0){
update_SO(count_61days,"61-90 days",recId,i);
}
else if(count_91days>0){
update_SO(count_91days,"91-120 days",recId,i);
}
else if((count_31days<1||count_31days=="null"||count_31days=="")&&(count_61days<1||count_61days=="null"||count_61days=="")&&(count_91days<1||count_91days=="null"||count_91days=="")){
update_SO(0,"120+ days",recId,i);
}
}
}
else{
log.debug("nt available");
}
}
catch (err) {
log.debug("err", err);
}
}
return {
/*beforeLoad: beforeLoad,
beforeSubmit: beforeSubmit,*/
afterSubmit: afterSubmit
};
/*Function to loadRecord the SO and update the changes transaction line item fields:
"Next Shipment ETA" and "Arriving Quantity"*/
function update_SO(avail_count,days_range,id,j){
try{
log.debug("avail_count",avail_count);
log.debug("days_range",days_range);
log.debug("id",id);
var objRecord = record.load({
type: record.Type.SALES_ORDER,
id:id,
isDynamic: true,
});
objRecord.selectLine({
sublistId : 'item',
line:j,
});
objRecord.setCurrentSublistText({
fieldId : 'custcol_jj_nextshipmenteta',
sublistId : 'item',
text:days_range ,
line :j,
});
objRecord.setCurrentSublistValue({
fieldId : 'custcol_jj_arrivingquantity',
sublistId : 'item',
value :avail_count ,
line :j,
});
objRecord.commitLine({
sublistId : 'item',
});
var edit_SO = objRecord.save();
log.debug("edit_SO",edit_SO);
}
catch(error){
log.debug("error",error);
}
}
});