- We will create a custom Suite let page in the XSEED account.
- In the Suite let page, we will add a list field to enter the wave number.
- User can enter the wave and click the print button.
- When entering a wave number to generate a shipping label, only the shipping label of the IF generated in this wave should get printed.
- We will create saved searches in script to get the sales order and its related IF generated from wave. Sorting of shipping label will be done in the search itself.
- We will add the search filter to generate shipping label only for Item Fulfillments with blank PRE-DISPATCH VERIFICATION DATE.
- We will generate shipping label in real time sorted in the priority transporter, courier details, item in the IF record. Here each shipping label will be in a separate page, first we show all the shipping label in which transporter is same. Then we again sort it by the transporter who have same courier details. And the shipping label is again sorted by the items in it. User can download the shipping labels using standard print button.
- We will update the existing shipping label template in the XSEED account for bulk shipping label. The shipping label template used by XSEED is “JJ Custom Shipping Label PDF Template XEPL-81″.
- The page size of the shipping label template is 4.00 x 6.00 inches(A6-Landscape), which will have only 1 shipping label per page.
/**
* @NApiVersion 2.1
* @NScriptType Suitelet
*/
/*************************************************************************************
***********
* XSEED Education Pte Ltd-IND-NS
*
* XSEED-592 : WMS Customization: Bulk Printing of shipping label
*
*
*************************************************************************************
***********
*
*
* Author: Jobin and Jismi IT Services LLP
*
* Date Created : 30-October-2023
*
* Description: The script help to open a suitelet page and user can enter the wave and script generate bulk shipping label for the IF created from wave.
*
* REVISION HISTORY
*
* @version 1.0 XSEED-592 : 30-October-2023 : Created the initial build by JJ0125
*
*
*************************************************************************************
**********/
define(['N/ui/serverWidget', 'N/search', 'N/https', 'N/file', 'N/render', 'N/record', 'N/runtime'],
(serverWidget, search, https, file, render, record, runtime) => {
/**
* Defines the Suitelet script trigger point.
* @param {Object} scriptContext
* @param {ServerRequest} scriptContext.request - Incoming request
* @param {ServerResponse} scriptContext.response - Suitelet response
* @since 2015.2
*/
const onRequest = (scriptContext) => {
try {
log.debug("Inside onRequest", "inside onRequest");
let request = scriptContext.request;
let response = scriptContext.response;
if (scriptContext.request.method === 'GET') {
let form = serverWidget.createForm({
title: 'Bulk Print Of Shipping Label'
});
let waveSearchObj = search.create({
type: "wave",
filters:
[
["type", "anyof", "Wave"],
"AND",
["mainline", "is", "T"]
],
columns:
[
search.createColumn({ name: "tranid", label: "Document Number" }),
search.createColumn({ name: "internalid", label: "Internal ID" })
]
});
let searchResultCount = waveSearchObj.runPaged().count;
log.debug("waveSearchObj result count", searchResultCount);
let waveArray = [];
waveSearchObj.run().each(function (result) {
// .run().each has a limit of 4,000 results
var waveSearchObj = {};
waveSearchObj.waveDocValue = result.getValue({
name: 'tranid'
});
waveSearchObj.waveIdValue = result.getValue({
name: 'internalid'
});
waveArray.push(waveSearchObj);
return true;
});
let waveField = form.addField({
id: 'custpage_wavedocid',
type: serverWidget.FieldType.SELECT,
label: 'Wave'
});
waveField.isMandatory = true;
waveField.addSelectOption({
value: "",
text: ""
});
//setting the value of account in the account field
for (let i = 0; i < waveArray.length; i++) {
let waveDocNo = waveArray[i].waveDocValue
waveField.addSelectOption({
value: waveDocNo,
text: waveDocNo
});
}
form.addSubmitButton({
label: 'Print'
});
scriptContext.response.writePage(form);
}
else {
let wavedocId = scriptContext.request.parameters.custpage_wavedocid;
let relatedIfResult = relatedIfSerachMethod(wavedocId);
let uniqueIfArray = Array.from(new Set(relatedIfResult));
log.debug("uniqueIfArray", uniqueIfArray);
if (uniqueIfArray == "" || uniqueIfArray == null) {
showAlert(scriptContext)
}
else {
let ifSearch = allWaveRelatedIf(uniqueIfArray);
log.debug("ifSearch", ifSearch);
if (ifSearch.length == 0) {
alertMesage(scriptContext)
}
else {
let renderer = render.create();
let templateId = 142;
renderer.setTemplateById(templateId)
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: 'record',
data: { ifRecord: ifSearch }
});
let pdfFile = renderer.renderAsPdf();
scriptContext.response.writeFile({
file: pdfFile,
isInline: true
});
}
}
}
}
catch (e) {
log.error("Error @onRequest", e);
}
var scriptObj = runtime.getCurrentScript();
log.debug('Remaining governance units: ' + scriptObj.getRemainingUsage());
}
function alertMesage(scriptContext) {
try {
let html = '<script>alert("Wave have no itemfulfilment that satisfies the condition shipped and predispatch verification");location.replace("https://4976925-sb1.app.netsuite.com/app/site/hosting/scriptlet.nl?script=1565&deploy=1&compid=4976925_SB1&whence=");</script>';
scriptContext.response.write(html);
}
catch (error) {
log.error("error@ alertfunction", error);
}
}
function relatedIfSerachMethod(wavedocId) {
try {
log.debug("inside relatedIfSerachMethod", true);
let waveSearchObj = search.create({
type: "wave",
filters:
[
["type", "anyof", "Wave"],
"AND",
["number", "equalto", wavedocId],
"AND",
["mainline", "is", "F"],
"AND",
["cogs", "is", "F"],
"AND",
["shipping", "is", "F"],
"AND",
["taxline", "is", "F"],
"AND",
["transactionlinetype", "noneof", "STAGE"]
],
columns:
[
search.createColumn({ name: "tranid", label: "Document Number" }),
search.createColumn({ name: "appliedtotransaction", label: "Applied To Transaction" }),
search.createColumn({ name: "applyingtransaction", label: "Applying Transaction" })
]
});
let searchResultCount = waveSearchObj.runPaged().count;
log.debug("waveSearchObj result count", searchResultCount);
let relatedIfArr = [];
waveSearchObj.run().each(function (result) {
let itemFulfilmentId = result.getValue({
name: "applyingtransaction",
label: "Applying Transaction"
})
relatedIfArr.push(itemFulfilmentId);
return true;
});
return relatedIfArr;
}
catch (e) {
log.error("Error @relatedIfSerachMethod", e);
}
}
function showAlert(scriptContext) {
try {
let html = '<script>alert("Wave has no related itemfulfilment");location.replace("https://4976925-sb1.app.netsuite.com/app/site/hosting/scriptlet.nl?script=1565&deploy=1&compid=4976925_SB1&whence=");</script>';
scriptContext.response.write(html);
}
catch (error) {
log.error("error@ alertfunction", error);
}
}
function allWaveRelatedIf(ifId) {
try {
log.debug("RelatedIF of Wave", ifId);
var itemfulfillmentSearchObj = search.create({
type: "itemfulfillment",
filters:
[
["type", "anyof", "ItemShip"],
"AND",
["status", "anyof", "ItemShip:C"],
"AND",
["internalid", "anyof", ifId],
"AND",
["mainline", "is", "T"],
"AND",
["custbody_jj_pre_dispatch_verifinc_date", "isempty", ""]
],
columns:
[
search.createColumn({
name: "shipaddress",
label: "Shippingaddress"
}),
search.createColumn({
name: "tranid",
join: "createdFrom",
label: "SOdocumentnumber"
}),
search.createColumn({
name: "tranid",
label: "IFdocumentnumber"
}),
search.createColumn({
name: "trandate",
label: "Date"
}),
search.createColumn({
name: "custbody_if_parent_waybill_no",
label: "parentwaybillno"
}),
search.createColumn({
name: "custbody_xs_if_transporter",
sort: search.Sort.ASC,
label: "transporter"
}),
search.createColumn({
name: "custbody_courier_detail",
sort: search.Sort.ASC,
label: "courierdetail"
}),
search.createColumn({
name: "custrecord_item_carton",
join: "CUSTRECORD_IF_CARTON_LINK",
sort: search.Sort.ASC,
label: "item"
}),
search.createColumn({
name: "custrecord_item_qty",
join: "CUSTRECORD_IF_CARTON_LINK",
label: "Quantity"
}),
search.createColumn({
name: "custrecord_if_description",
join: "CUSTRECORD_IF_CARTON_LINK",
label: "Itemdescription"
}),
search.createColumn({
name: "custrecord_if_child_waybill_no",
join: "CUSTRECORD_IF_CARTON_LINK",
label: "Childwaybillno"
}),
search.createColumn({
name: "custrecord_if_carton_no",
join: "CUSTRECORD_IF_CARTON_LINK",
label: "Cartonno"
}),
search.createColumn({
name: "custbody_xd_crtn_no",
label: "IFcartonno"
}),
search.createColumn({
name: "custrecord_if_carton_weight",
join: "CUSTRECORD_IF_CARTON_LINK",
label: "cartonweight"
})
]
});
var searchResultCount = itemfulfillmentSearchObj.runPaged().count;
log.debug("itemfulfillmentSearchObj result count", searchResultCount);
let printItemFulfilmentArr = [];
itemfulfillmentSearchObj.run().each(function (result) {
var singleLine = {};
for (var i = 0; i < itemfulfillmentSearchObj.columns.length; i++) {
if (i == 5) {
singleLine[itemfulfillmentSearchObj.columns[i].label] = result.getText(itemfulfillmentSearchObj.columns[i])
}
else {
singleLine[itemfulfillmentSearchObj.columns[i].label] = result.getValue(itemfulfillmentSearchObj.columns[i])
}
}
printItemFulfilmentArr.push(singleLine)
return true;
});
log.debug("printIFArr", printItemFulfilmentArr);
return printItemFulfilmentArr;
}
catch (e) {
log.error("Error @allWaveRelatedIf", e);
}
}
return { onRequest }
});