Print Warehouse Label

Jira Code: ACL-10

Add a custom Button in the inventory item record and print a warehouse label using that Button. The print warehouse label has dimensions of 152.4mm high x 101.6mm from which the part number needs to reference from the field “itemid” and description needs to reference from the field “sales description” Stock units value needs to reference from the field id “stock unit”

Advanced PDF Template

<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
	<link name="NotoSans" type="font" subtype="truetype" src="${nsfont.NotoSans_Regular}" src-bold="${nsfont.NotoSans_Bold}" src-italic="${nsfont.NotoSans_Italic}" src-bolditalic="${nsfont.NotoSans_BoldItalic}" bytes="2" />
	<#if .locale == "zh_CN">
		<link name="NotoSansCJKsc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKsc_Regular}" src-bold="${nsfont.NotoSansCJKsc_Bold}" bytes="2" />
	<#elseif .locale == "zh_TW">
		<link name="NotoSansCJKtc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKtc_Regular}" src-bold="${nsfont.NotoSansCJKtc_Bold}" bytes="2" />
	<#elseif .locale == "ja_JP">
		<link name="NotoSansCJKjp" type="font" subtype="opentype" src="${nsfont.NotoSansCJKjp_Regular}" src-bold="${nsfont.NotoSansCJKjp_Bold}" bytes="2" />
	<#elseif .locale == "ko_KR">
		<link name="NotoSansCJKkr" type="font" subtype="opentype" src="${nsfont.NotoSansCJKkr_Regular}" src-bold="${nsfont.NotoSansCJKkr_Bold}" bytes="2" />
	<#elseif .locale == "th_TH">
		<link name="NotoSansThai" type="font" subtype="opentype" src="${nsfont.NotoSansThai_Regular}" src-bold="${nsfont.NotoSansThai_Bold}" bytes="2" />
	</#if>
    <style type="text/css">* {
		<#if .locale == "zh_CN">
			font-family: NotoSans, NotoSansCJKsc, sans-serif;
		<#elseif .locale == "zh_TW">
			font-family: NotoSans, NotoSansCJKtc, sans-serif;
		<#elseif .locale == "ja_JP">
			font-family: NotoSans, NotoSansCJKjp, sans-serif;
		<#elseif .locale == "ko_KR">
			font-family: NotoSans, NotoSansCJKkr, sans-serif;
		<#elseif .locale == "th_TH">
			font-family: NotoSans, NotoSansThai, sans-serif;
		<#else>
			font-family: NotoSans, sans-serif;
		</#if>
		}
		table {
            font-size: 9pt;
            margin-top: 10px;
            table-layout: absolute;
            page-break-inside: avoid;
          	align: center
        }
		td p {align:center}
</style>
</head>
<body style=" width:4in; height:6in">
   
<table style="align:center; width:3.7in; height:4in"><tr>
	<td style="margin-top:-15px;"><img src="http://shopping.na2.netsuite.com/core/media/media.nl?id=333&c=3929178&h=fe58a397363049cf8aea" style="align:center; width: 140px; height: 63px;" /></td>
	</tr>
	<tr>
	<td> </td>
	</tr>
	<tr>
	<td><strong><span style="font-size:34px;">${record.itemid}</span></strong></td>
	</tr>
  <tr>
	<td>  </td>
	</tr>
	<tr>
	<td><span style="font-size:24px;">${record.displayname}</span></td>
	</tr>
	<tr>
	<td>  </td>
	</tr>
  <tr>
	<td> </td>
	</tr>
 <tr>
   <td><b><span style="font-size:20px;"><i>${record.custitem_product_identification}</i></span></b></td>
	</tr>
  <tr>
	<td> </td>
	</tr>
  <tr>
	<td> </td>
	</tr>
  <tr>
	<td> </td>
	</tr>
  	<tr>
	<td><span style="font-size:20px;">Stock Units: ${record.stockunit}</span></td>
	</tr>
	<tr>
	<td> </td>
	</tr>
  <tr>
	<td> </td>
	</tr>
  <tr>
	<td> </td>
	</tr>
  	<tr>
	<td align="center"><table style="padding-left:-10px;margin-bottom:-10px;"><tr>
      <td><barcode bar-width="1.4" codetype="code128" showtext="true" value="${record.itemid}"></barcode></td>
	</tr>
</table></td>
	</tr>
    </table>
</body>
</pdf>

Suitelet

/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 * @NModuleScope SameAccount
 */
/*******************************************************************************
* CLIENTNAME:ACL Welding Supply
* ACL-10
* Print Warehouse Label
* **************************************************************************
* Date : 03-05-2019
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This script is to add a button in item record  to print the Warehouse Label.
* Date created : 03-05-2019
*
* REVISION HISTORY
*
* Revision 1.0 ${03-05-2019} nd :marg created
* 
*
******************************************************************************/
define(['N/file','N/render','N/record','N/search'],

function(file,render,record,search) {
   
    function onRequest(context) {
        try{
             var internalId = context.request.parameters.item_id;
          			     var type = context.request.parameters.item_type;
            			  log.debug('type',type)
            
          				   var objRecord = record.load({
                  		   type: type, 
                 		   id: internalId
             			   });

             			   var myFile = render.create();

                        var template = 144;
                        myFile.setTemplateById(template);


                        myFile.addRecord({
                            templateName: 'record',
                            record: objRecord
                        });
                        
                        var transactionFile = myFile.renderAsPdf();

                        context.response.writeFile(transactionFile, true);
                   


        }catch(error){
            log.error('error @ onRequest',error)
        }

    }

    return {
        onRequest: onRequest
    };
    
});


User Event

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
/*******************************************************************************
* CLIENTNAME:ACL Welding Supply
* ACL-10
* Print Warehouse Label
* **************************************************************************
* Date : 03-05-2019
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This script is to add a button in item record  to print the Warehouse Label.
* Date created : 03-05-2019
*
* REVISION HISTORY
*
* Revision 1.0 ${03-05-2019} nd :marg created
* 
*
******************************************************************************/
define([],

function() {
   
    
    function beforeLoad(scriptContext) {

    	try{
    		var itemRec =  scriptContext.form;
    	 scriptContext.form.clientScriptFileId = 2628561;
        	 if(scriptContext.type == 'view'){
        		
        		 var button = itemRec.addButton({
             		id: 'custpage_printlabel',
             		label :'Print Warehouse Label',
             		 functionName: 'printbuttonClick'
             	 });
     		}
    	}catch(err){
    		log.debug('error @ beforeLoad',err)
    	}
    	

    

    }

   

    return {
        beforeLoad: beforeLoad
    };
    
});

Client Script


/*******************************************************************************
* CLIENTNAME:ACL Welding Supply
* ACL-10
* Print Warehouse Label
* **************************************************************************
* Date : 03-05-2019
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This script is to to define the action of print button
* Date created : 03-05-2019
*
* REVISION HISTORY
*
* Revision 1.0 ${03-05-2019} nd :marg created
* 
*
******************************************************************************/
define(['N/currentRecord','N/url'],

function(currentRecord,url) {
    
   

    function printbuttonClick(){
    	try{
    		var record = currentRecord.get();
    		var int_id = record.id;
    		var item_type = record.type;
    		console.log('item_type',item_type)
    		get_url = url.resolveScript({
	    		scriptId: "customscript_jj_acl_10_sl_print_wre_hous",
	           deploymentId: "customdeploy_jj_acl_10_prnt_wre_hse_labe"
	        });	
   		 	
	     get_url += ('&item_id=' + int_id + '&item_type=' + item_type);
	        window.open(get_url);
    		
    	}catch(er){
    		console.log('error at printbuttonClick',er)
    	}
    }
    

    return {
         printbuttonClick:printbuttonClick
    };
    
});

Leave a comment

Your email address will not be published. Required fields are marked *