MoCheeks
12/31/2021, 12:22 PMbattk
12/31/2021, 1:00 PMbattk
12/31/2021, 1:00 PMMoCheeks
12/31/2021, 1:16 PM/**
*@NApiVersion 2.1
*@NScriptType Suitelet
*/
define([
"N/record",
"N/ui/serverWidget",
"N/search",
"N/url",
"N/ui/message",
"N/http",
"N/xml",
"N/format",
"N/https",
"N/runtime",
"N/redirect",
"N/task"
], function (record, serverWidget, search, url, message, http, xml, format, https, runtime, redirect, task){
function onRequest(context) {
if (context.request.method === "GET"){
context.response.writePage(createGetForm(context));
}else{
// let tranArray = getSerialData(context);
let itemFulfillmentId = fulfillSOLines(getSerialData(context));
//context.response.writePage(createPostForm(context));
// schedulePickups(context);
// createTask();
// redirectToScheduledShipping();
//IS THIS UPDATING?
//redirectToSelf();
}
}
function createGetForm(context){
log.debug('context', context)
let form = serverWidget.createForm({title: "Unit Shipping", hideNavBar: false, });
const sbtButton = form.addSubmitButton({ label: "Fulfill" });
form.addField({id: 'custpage_serial1', label: 'First Serial', type: serverWidget.FieldType.TEXT}).updateDisplayType({displayType: serverWidget.FieldDisplayType.NORMAL});
form.addField({id: 'custpage_serial2', label: 'Second Serial', type: serverWidget.FieldType.TEXT}).updateDisplayType({displayType: serverWidget.FieldDisplayType.NORMAL});
// form.clientScriptModulePath = 'SuiteScripts/rjmScripts/LTL Project/ShipEngine - Pickups/shipEngine_scheduleLTL_pickups_cs.js';
return form;
}
function getSerialData(context){
try{
let firstSerial = context.request.parameters.custpage_serial1;
let secondSerial = context.request.parameters.custpage_serial2;
let tranArray = [];
let mySearch = search.create({
type: "salesorder",
filters:
[
["subsidiary","anyof","2"],
"AND",
["type","anyof","SalesOrd"],
"AND",
["status","anyof","SalesOrd:B","SalesOrd:D","SalesOrd:E"],
"AND",
["location","anyof","16"],
"AND",
["mainline","is","F"],
"AND",
["shipping","is","F"],
"AND",
["taxline","is","F"],
"AND",
["custbody_sotype","anyof","7"],
"AND",
[["serialnumber","is",firstSerial],"OR",["serialnumber","is",secondSerial]]
],
columns:
[
search.createColumn({name: "internalid", label: "Internal ID"}),
search.createColumn({name: "type", label: "Type"}),
search.createColumn({name: "trandate", sort: search.Sort.ASC, label: "Date"}),
search.createColumn({name: "tranid", label: "Document Number"}),
search.createColumn({name: "entity", label: "Name"}),
search.createColumn({name: "item", label: "Item"}),
search.createColumn({name: "serialnumber", label: "Transaction Serial/Lot Number"}),
search.createColumn({name: "transactionlinetype", label: "Transaction Line Type"}),
search.createColumn({name: "internalid", join: "inventoryDetail", label: "Internal ID"}),
search.createColumn({name: "line", label: "Line ID"}),
search.createColumn({name: "lineuniquekey", label: "Line Unique Key"}),
search.createColumn({name: "formulatext", formula: "CASE WHEN {customermain.parent.id} IN ('148543') THEN 'PalletId' ELSE 'NoPalletId' END", label: "Formula (Text)" }),
search.createColumn({name: "inventorynumber", join: "inventoryDetail", label: " Number"}),
]
});
let myResultSet = mySearch.run().getRange({start: 0, end: 2});
myResultSet.forEach(function(result){
let rowObj = {
soInternalId : result.getValue({name: 'internalid'}),
serialNumber : result.getValue({name: 'serialnumber'}),
serialId : result.getValue({name: "internalid", join: "inventoryDetail"}),
lineId : result.getValue({name: 'line'}),
lineUniqueKey : result.getValue({name: 'lineuniquekey'}),
palletIdReq : result.getValue({name: 'formulatext', formula: "CASE WHEN {customermain.parent.id} IN ('148543') THEN 'PalletId' ELSE 'NoPalletId' END"}),
inventoryNumber : result.getValue({name: "inventorynumber", join: "inventoryDetail"}),
}
log.debug('rowObj', rowObj);
tranArray.push(rowObj);
return true;
});
log.debug('tranArray', tranArray);
let soIdArray = [];
tranArray.forEach(element => {
soIdArray.push(element.soInternalId)
return true;
})
let sameSO = soIdArray.every(element => element == soIdArray[0]);
if(!sameSO){
//TODO display page showing error with serial and Sales Order detail
log.error('SO Mismatch!', 'Serial Numbers are not for the same Sales Order....Exiting function');
return;
};
// log.debug('soIdArray', soIdArray);
// log.debug('same SO?', sameSO);
return tranArray;
}catch(e){
log.debug('Caught Error in Get Serial Data', e);
}
};
function fulfillSOLines(tranArray){
try{
let itemFulfillment = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: tranArray[0].soInternalId,
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: true,
});
let lineCount = itemFulfillment.getLineCount({sublistId: 'item'});
log.debug('line Count', lineCount);
for(let i = 0; i < lineCount; i++){
itemFulfillment.selectLine({sublistId: 'item', line: i});
let fulfill = itemFulfillment.getCurrentSublistValue({sublistId: 'item', fieldId: 'itemreceive'})
let subRec = itemFulfillment.getCurrentSublistSubrecord({
sublistId: 'item',
fieldId: 'inventorydetail'
});
log.debug('line', i);
log.debug('subRec', subRec);
log.debug('fulfill?', fulfill);
}
tranArray.forEach(rowObj => {
itemFulfillment.selectLine({sublistId: 'item',line: rowObj.lineId });
itemFulfillment.removeCurrentSublistSubrecord({sublistId: 'item', fieldId: 'inventorydetail'})
itemFulfillment.setSublistValue({sublistId: 'item', fieldId: 'itemreceive', line: rowObj.lineId, value: true})
itemFulfillment.setSublistValue({sublistId: 'item', fieldId: 'quantity', line: rowObj.lineId, value: 1})
itemFulfillment.setSublistValue({sublistId: 'item', fieldId: 'location', line: rowObj.lineId, value: 16})
itemFulfillment.setSublistValue({sublistId: 'item', fieldId: 'class', line: rowObj.lineId, value: 25})
itemFulfillment.removeSublistSubrecord({sublistId: 'item', fieldId: 'inventorydetail', line: 2 })
let serialSubRec = itemFulfillment.getSublistSubrecord({sublistId: 'item', fieldId: 'inventorydetail', line: rowObj.lineId})
log.debug('serialSub', serialSubRec);
serialSubRec.selectNewLine({sublistId: 'inventoryassignment'})
serialSubRec.setCurrentSublistValue({sublistId: 'inventoryassignment', fieldId: 'quantity', line: 0, value: 1 })
serialSubRec.setCurrentSublistValue({sublistId: 'inventoryassignment', fieldId: 'issueinventorynumber', line: 0, value: rowObj.inventoryNumber})
serialSubRec.commitLine({sublistId: 'inventoryassignment'})
itemFulfillment.commitLine({sublistId: 'item', ignoreRecalc: true});
})
let itemFulfillmentId = itemFulfillment.save({ignoreMandatoryFields: true});
return itemFulfillmentId;
}catch(e){
log.debug('Caught Error in Fulfillment', e);
}
}
return {
onRequest: onRequest,
};
});
battk
12/31/2021, 1:17 PMbattk
12/31/2021, 1:18 PMbattk
12/31/2021, 1:18 PMbattk
12/31/2021, 1:19 PMbattk
12/31/2021, 1:19 PMMoCheeks
12/31/2021, 1:20 PMbattk
12/31/2021, 1:21 PMbattk
12/31/2021, 1:21 PMbattk
12/31/2021, 1:22 PMMoCheeks
12/31/2021, 1:22 PMbattk
12/31/2021, 1:22 PMMoCheeks
12/31/2021, 1:23 PMbattk
12/31/2021, 1:24 PMbattk
12/31/2021, 1:24 PMbattk
12/31/2021, 1:24 PMMoCheeks
12/31/2021, 1:25 PMbattk
12/31/2021, 1:25 PMMoCheeks
12/31/2021, 1:26 PMMoCheeks
12/31/2021, 1:26 PMbattk
12/31/2021, 1:26 PMMoCheeks
12/31/2021, 1:28 PMbattk
12/31/2021, 1:29 PMMoCheeks
12/31/2021, 1:29 PMMoCheeks
12/31/2021, 1:29 PMMoCheeks
12/31/2021, 1:38 PMitemFulfillment.selectLine({sublistId: 'item',line: 0 });
itemFulfillment.removeCurrentSublistSubrecord({sublistId: 'item', fieldId: 'inventorydetail'})
itemFulfillment.setCurrentSublistValue({sublistId: 'item', fieldId: 'itemreceive', line: 0, value: true})
itemFulfillment.setCurrentSublistValue({sublistId: 'item', fieldId: 'quantity', line: 0, value: 1})
itemFulfillment.setCurrentSublistValue({sublistId: 'item', fieldId: 'location', line: 0, value: 16})
itemFulfillment.setCurrentSublistValue({sublistId: 'item', fieldId: 'class', line: 0, value: 25})
itemFulfillment.removeCurrentSublistSubrecord({sublistId: 'item', fieldId: 'inventorydetail', line: 0 })
let serialSubRec = itemFulfillment.getCurrentSublistSubrecord({sublistId: 'item', fieldId: 'inventorydetail', line: 0})
log.debug('serialSub', serialSubRec);
serialSubRec.selectNewLine({sublistId: 'inventoryassignment'})
serialSubRec.setCurrentSublistValue({sublistId: 'inventoryassignment', fieldId: 'quantity', line: 0, value: 1 })
serialSubRec.setCurrentSublistValue({sublistId: 'inventoryassignment', fieldId: 'issueinventorynumber', line: 0, value: '99322'})
serialSubRec.commitLine({sublistId: 'inventoryassignment'})
itemFulfillment.commitLine({sublistId: 'item', ignoreRecalc: true});
MoCheeks
12/31/2021, 1:38 PMbattk
12/31/2021, 1:40 PMMoCheeks
12/31/2021, 1:50 PM{"type":"inventorydetail","isDynamic":true,"fields":{"itemdescription":"Amigo ValueShopper 34","nlloc":"0","nlsub":"2","ignoreqtyvalidation":"F","trandate":"12/31/2021","_eml_nkey_":"4086366_SB1~5~3~N","type":"inventorydetail","subrecord_parent_tran_type":"ItemShip","nsapiCT":"1640958510188","sys_id":"-1885723381998080","nluser":"5","nldept":"1","subrecord_transform_from_parent_id":"11453110","subrecord_transform_from_parent_tran_type":"SalesOrd","tolocationusesbins":"F","item":"24532","quantity":"1.0","templatestored":"F","sys_parentid":"1885722703209829","entryformquerystring":"orderline=1&item=24532&quantity=1.0&subrecord_transform_from_parent_id=11453110&trandate=12/31/2021&location=16&uitype=LOH_STRICT_VALIDATION&wavefulfillment=&subrecord_transform_from_parent_tran_type=salesord&subrecord_parent_tran_type=itemship","nlrole":"3","_csrf":"t2ZHtQNVPkcmA9beHI-VEzWzol2rzU455RYdtV1t0edXp2Ed6FrssIHIQnFVo3wO-ZMcvy5iPmb-G7lvx_avAuBm1ncWWm-8dB5IHtFul3w4IqnxR1D9tuLsLjBmeqLzLlPBC5QBZw0PrWLUPF1Cq_dKWzU7WjcLOx13RvHwfDQ=","uitype":"LOH_STRICT_VALIDATION","baseunitquantity":"1.0","baserecordtype":"inventorydetail","totalquantity":"0","orderline":"1","haslines":"F","tolocation":"-1","customform":"-10820","location":"16"},"sublists":{"inventoryassignment":{"currentline":{"basequantityavailable":"","binnumber":"","binnumber_display":"","existingexpdate":"","existinginventorynumber":"","expirationdate":"","internalid":"-1","inventorydetail":"-1","inventorystatus":"","inventorystatus_display":"","issueinventorynumber":"","lotquantityavailable":"","numberedrecordid":"","packcarton":"","pickcarton":"","quantity":"1","quantityavailable":"","quantitystaged":"","receiptinventorynumber":"","sequencenumber":"","sys_id":"-1885723381798710","sys_parentid":"-1885723381793046","tobinnumber":"","tobinnumber_display":"","toinventorystatus":"","toinventorystatus_display":"","totalquantityavailable":"","#":"1"}}}}
battk
12/31/2021, 1:56 PMbattk
12/31/2021, 1:56 PMMoCheeks
12/31/2021, 1:58 PMMoCheeks
12/31/2021, 1:58 PM