Jira code: AN-2 Task 3
Set one Finished Goods Tag button in the WO record. On that button click, it will create the PDF tag with the data from the SO such as Store Name, SO #, Customer PO#, and Ship Date
User Event Script
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/**
* Script Description: This script is for setting a buttons in the Work Order record
*/
/*******************************************************************************
* * AN * *
* **************************************************************************
* Date:06/11/18
* Script name: AN UE WO Buttons
* Script id: customscript_an_ue_wo_buttons
* Deployment id: customdeploy_an_ue_wo_buttons
* Applied to: Work order
*
******************************************************************************/
define(['N/search'],
function(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) {
try {
var CustRec=scriptContext.form;
if(scriptContext.type == 'view'){
//Loading Client Script
CustRec.clientScriptFileId = 10173;
var recId=scriptContext.newRecord.id;
log.debug({
title: 'recId',
details: recId
});
var transactionSearchObj = search.create({
type: "transaction",
filters:
[
["mainline","is","T"],
"AND",
["internalidnumber","equalto",recId],
"AND",
["createdfrom.type","anyof","SalesOrd"]
],
columns:
[
search.createColumn({
name: "tranid",
sort: search.Sort.ASC,
label: "Document Number"
})
]
});
var searchResultCount = transactionSearchObj.runPaged().count;
log.debug("transactionSearchObj result count",searchResultCount);
if(searchResultCount==0){
//Set Raw Material Tag button
var stockTag=CustRec.addButton({
id:'custpage_stock_tag_btn',
label:'Stock Tag',
functionName:'stockTag'
});
}
else{
//Set fINISHED Goods Tag button
var finishedGoodsTag=CustRec.addButton({
id:'custpage_finished_goods_tag_btn',
label:'Finished Goods Tag',
functionName:'finishedGoodsTag'
});
}
}
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
}
return {
beforeLoad: beforeLoad
};
});
Client Script
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/**
* Script Description: This script defining the function of button
*/
/*******************************************************************************
* * AN * *
* **************************************************************************
* Date:6/11/18
* Script name: AN CS WO Btn Action
* Script id: customscript_an_cs_wo_btn_action
* Deployment id: customdeploy_an_cs_wo_btn_action
* Applied to: Work order
*
******************************************************************************/
define(['N/currentRecord','N/record','N/url'],
function(currentRecord,record,url) {
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
function pageInit(scriptContext) {
try {
console.log("In");
} catch (e) {
console.log(e.name,e.message);
}
}
function finishedGoodsTag() {
try {
console.log("finishedGoodsTag");
var recID = currentRecord.get().id;
var parameterObj = {
intenalId: recID
};
var recObj = record.load({ type: "workorder", id: recID });
var labelUrl = url.resolveScript({
scriptId: "customscript_sl_finished_goods_tag",
deploymentId: "customdeploy_sl_finished_goods_tag",
returnExternalUrl: false,
params: parameterObj
});
var childwindow = window.open(labelUrl);
} catch (e) {
console.log(e.name,e.message);
}
}
return {
pageInit: pageInit,
finishedGoodsTag: finishedGoodsTag
};
});
XML Code
<?xml version="1.0"?>
<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
<macrolist>
<macro id="nlfooter">
<table class="footer" style="width: 100%;">
<tr>
<td align="center" class="pagenumber">
<pagenumber /> of
<totalpages />
</td>
</tr>
</table>
</macro>
</macrolist>
<style type="text/css">
span.title {
font-size: 24pt;
}
span.pagenumber {
font-size: 10pt;
}
span.number {
font-size: 16pt;
}
.pagenumber {
font-size: 6pt;
}
.addressheader {
font-size: 9pt;
}
span.itemname {
font-weight: bold;
line-height: 150%;
}
barcode{
width: 450px;
height:75px;
}
</style>
</head>
<body header="nlheader" header-height="10%" footer="nlfooter" footer-height="10pt" padding="0.35in 0.35in 0.35in 0.35in" size="A4-LANDSCAPE">
<br></br>
<p class="title" align="center" style="font-size:28px;">
<b>Finished Goods Tag</b>
</p>
<!-- <table>
<tr>
<td>
<span class="title">
<b>Raw Material Tag</b>
</span>
</td>
</tr>
</table> -->
ReplacewithContent
</body>
</pdf>
Suitelet
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
/**
* Script Description: PDF Creation
*/
/*******************************************************************************
* * AN * *
* **************************************************************************
* Date:7/11/18
* Script name: AN SL Finished Goods Tag
* Script id: customscript_sl_finished_goods_tag
* Deployment id: customdeploy_sl_finished_goods_tag
*
******************************************************************************/
define(['N/file','N/render','N/record','N/search'],
function(file,render,record,search) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
function onRequest(context) {
try {
var internalId = context.request.parameters.intenalId;
log.debug({
title: "record internalId",
details: internalId
});
var recordObj = record.load({ type: "workorder", id: internalId });
var soID=recordObj.getValue({
fieldId: 'createdfrom'
});
var itemName=recordObj.getText({
fieldId: 'assemblyitem'
});
var soDtls = search.lookupFields({
type: record.Type.SALES_ORDER,
id: soID,
columns: ['tranid','otherrefnum','shipdate']
});
var soNO=soDtls.tranid;
var customer=soDtls.otherrefnum;
var shipDate=soDtls.shipdate;
log.debug({
title: "soNO",
details: soNO
});
var bodyContent = '';
var numpages = 0;
var content = '<div style="margin-left: 5%;border:1px;"> <table style="width: 95%; margin-top: 10px;font-size:24px;"> <tr> <td align="center"><b> Store Name: '+itemName+'</b></td> </tr> <tr><td> Replacewithitemcode </td> </tr> <tr> <td align="center"><b> SO#: '+soNO+' </b></td> </tr> <tr><td> ReplacewithSO </td></tr><tr> <td align="center"><b> Customer PO#: '+customer+'</b> </td> </tr> <tr><td> ReplacewithCustomer </td></tr> <tr> <td align="center"><b> Ship Date: '+shipDate+'</b> </td> </tr> <tr><td> ReplacewithShipDate </td> </tr> <tr><td> </td> </tr> </table> </div><br></br>';
if((itemName!=null) && (itemName!=undefined) && (itemName!='')){
content = content.replace("Replacewithitemcode", '<barcode codetype="code128" style="width: 650px;" align="center" showtext="false" value="'+itemName+'"> </barcode>');
}
else{
content = content.replace("Replacewithitemcode", '<span></span>');
}
if((soNO!=null) && (soNO!=undefined) && (soNO!='')){
content = content.replace("ReplacewithSO", '<barcode codetype="code128" align="center" showtext="false" value="'+soNO+'"> </barcode>');
}
else{
content = content.replace("ReplacewithSO", '<span></span>');
}
if((customer!=null) && (customer!=undefined) && (customer!='')){
content = content.replace("ReplacewithCustomer", '<barcode codetype="code128" align="center" showtext="false" value="'+customer+'"> </barcode>');
}
else{
content = content.replace("ReplacewithCustomer", '<span></span>');
}
if((shipDate!=null) && (shipDate!=undefined) && (shipDate!='')){
content = content.replace("ReplacewithShipDate", '<barcode codetype="code128" align="center" showtext="false" value="'+shipDate+'"></barcode>');
}
else{
content = content.replace("ReplacewithShipDate", '<span></span>');
}
bodyContent += content;
var myXMLFile = file.load({
id: '10460'
});
var xmlContent = myXMLFile.getContents();
xmlContent = xmlContent.replace("ReplacewithContent",bodyContent);
var pdfFile = render.xmlToPdf({
xmlString: xmlContent
});
pdfFile.name = "finishedGoodsTag.pdf"
context.response.writeFile(pdfFile,true);
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
}
return {
onRequest: onRequest
};
});