How to Customize Order Assembly Guide Documents


Step 1: Go to Smart Documents 

  • Create a new smart document, label it something related to Order Assembly Guide Customized

  • Set Record Type to Fulfillment Process

  • Set API Version to Beta

  • Use the script directly below and insert it into the text box under the drop-down options



Pro Tip: This specific script is designed to help customize the Cartonization for the Order Assembly Guide. If you do not want that customization included, you will need to delete those parts of the script below. You can fully customize this script to perform the exact customization you are looking for. 


<div style="padding: 20px; font-family: sans-serif; line-height: 1.1;">

<div dir="ltr" style="font-weight: 400; text-align: start; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 11px;">&nbsp;</div>

<h4 style="text-align: center;">Order Assembly Guide</h4>

<p style="text-align: center;"><img src="${utils.generateBase64Barcode($record.orderNo.toString())}" alt="" width="300" height="50" /></p>

<table border="0" width="100%" cellspacing="0" cellpadding="3">

<tbody>

<tr>

<td width="35%">Order No</td>

<td width="65%"><strong>$!record.orderNo</strong></td>

</tr>

<tr>

<td>Carrier</td>

<td><strong>$!scriptOutput.carrierMap.get($record.carrierId).label</strong></td>

</tr>

<tr>

<td>LOB</td>

<td><strong>$!scriptOutput.lobMap.get($record.lobId).name</strong></td>

</tr>

<tr>

<td>Ful. Process No</td>

<td><strong>$!parentRecord.processNo</strong></td>

</tr>

<tr>

<td>Carton Type</td>

<td><strong>$!scriptOutput.cartonMap.get($record.orderNo).carton</strong></td>

</tr>

<tr>

<td>Record # (Order Pos.)</td>

<td><strong>$!scriptOutput.orderPositionMap.get($record.orderNo.toString()).intValue()</strong></td>

</tr>

<tr>

<td>&nbsp;Customer</td>

<td>&nbsp;<strong>$!scriptOutput.customerMap.get($record.orderNo).customer</strong></td>

</tr>

</tbody>

</table>

<p>&nbsp;</p>

<table border="1" width="100%" cellspacing="0" cellpadding="3">

<tbody>

<tr>

<td width="75%">SKU</td>

<td width="25%; text-align: right;">Quantity</td>

</tr>

<!--#foreach($lineItem in $record.lineItems)-->

<tr>

<td><strong>$!lineItem.sku</strong></td>

<td align="right"><strong>$!lineItem.shippedQty</strong></td>

</tr>

<!--#end--></tbody>

</table>

<p>&nbsp;</p>

</div>

<p>#if($record.giftMessage)</p>

<div style="page-break-before: always;">

<table border="0" width="100%" cellspacing="0" cellpadding="3">

<tbody>

<tr>

<td style="width: 35%; text-align: center;" colspan="2" width="35%">

<p><strong>Order No:</strong>&nbsp; $!record.orderNo&nbsp;</p>

<p><strong>Gift Message:</strong></p>

</td>

</tr>

<tr>

<td style="width: 35%; text-align: center;" colspan="2" width="35%">$!record.giftMessage</td>

</tr>

</tbody>

</table>

</div>

<p>#else #end</p>




Step 2: Go to Script Table and Create a New Script


  • Name the Script something detailed that will help you know what action the script is performing

  • Select Smart Document from the Script Type drop-down

  • Some general information will populate in the Code box, you can delete this if you want and enter in the script below

  • Click Save


Pro Tip: This Script is customized specifically for cartonization. You can delete this action from the script and personalize it for what your particular needs are for the Order Assembly Guide. 


//

// This Script works with a SmartDoc to create a 4x6 Order Assembly Guide

//   The corresponding SmartDoc has a Record Type of Fulfillment Process and a record subType of Order sorted by Order Layout Position

//   The things this script does:

//

//      1 Populates an Order position map for the Smart Doc

//      2 Populates a Carrier map for the Smart Doc

//      3 Populates a LOB map for the Smart Doc

//

//

// A Smart Document script can take an API Model object as input (based on selection in Smart Document Template),

// and can produce output that is available to the Smart Document Template:

//

// A script of this type has the following variables available:

//

// record - object - an instance of an Infoplus API model, for the record the template is being rendered against.

//

// infoplusApi - object which provides access to the Infoplus API, specifically, with the following methods:

//    .search(type, filter, pageNo, limit, orderBy) - run a search query in the Infoplus API.

//    .getById(type, id) - get the record of the specified type identified by the id.

//    .getTags(type, id) - get the tags from Infoplus for the specified record.

//    .constructModel(type) - used to construct an API model object of the given type.

//        - See the https://developer.infopluscommerce.com/ for more details.

// utils - object with the following methods:

//    .log(message) - add a line to the Script Output's log.

// output - object - where script can put values into for the Smart Document to access, via method: put(key, value)

//

// More data is available if the script record type uses a record subtype:

// Order -> Line :

//    orderLineList - list of Line Items for the order

// Order -> Each :

//    orderLineList - list of Line Items for the order

//    itemMap - map of all Items on the order where the key is the item's SKU

// ASN -> Line :

//    lineItems - list of Item Receipts for the ASN

// ASN -> Each :

//    lineItems - list of Item Receipts for the ASN

//    itemMap - map of all Items on the ASN where the key is the item's SKU

// FulfillmentProcess -> Order :

//    orderList - list of Orders in the Fulfillment Process

// FulfillmentProcess -> Order Line :

//    orderList - list of Orders in the Fulfillment Process

//    orderLineMap - map of all Order Lines in the process where the key is the line item id

// FulfillmentProcess -> Each :

//    orderList - list of Orders in the Fulfillment Process

//    orderLineMap - map of all Order Lines in the process where the key is the line item id

//    itemMap - map of all Items in the process where the key is the item's SKU

// FulfillmentProcess -> Item :

//    orderList - list of Orders in the Fulfillment Process

//    itemMap - map of all Items in the process where the key is the item's SKU

// FulfillmentProcess -> Pick Work :

//    orderList - list of Orders in the Fulfillment Process

//    workMap - map of all pick Work records in the process where the key is the work id

//

// Example with an Order record:



var OUTSIDE_VENDOR_SERVICE_TYPE_ID = 97;

var KIT_SERVICE_TYPE_ID = 98;



/////////////////////////////////////////////////////////////////////////

// look up all carriers & LOB & cartonType & customer's on the process //

/////////////////////////////////////////////////////////////////////////

var carrierMap = {};

var lobMap = {};

var cartonMap = {};

var customerMap = {};



///////////////////////////////////////////////

// setup a map of order positions by orderNo //

///////////////////////////////////////////////

var orderPositionMap = {};

var position = 0;

////////////////////////////////////////////////////////////////////////////////

// Noting the smart doc can reference/pull in the values in the map via:      //

//                                                                            //

// $!scriptOutput.orderPositionMap.get($record.orderNo.toString()).intValue() //

////////////////////////////////////////////////////////////////////////////////

for(var i=0; i<orderList.size(); i++)

{

    ///////////////////////////////////////////////////////

    // exclude outside vendor orders from being included //

    ///////////////////////////////////////////////////////

    var order = orderList.get(i);

    utils.log("Evaluating order " + order.orderNo);

   

    if(order.warehouseServiceTypeId == OUTSIDE_VENDOR_SERVICE_TYPE_ID)

    {

       utils.addSubRecordToSkip(order.orderNo);

       utils.log("Skipping Outside Vendor order " + order.orderNo);

       continue;

    }



    if(order.warehouseServiceTypeId == KIT_SERVICE_TYPE_ID)

    {

       utils.addSubRecordToSkip(order.orderNo);

       utils.log("Skipping Kit order " + order.orderNo);

       continue;

    }



    ///////////////////////////////////////////

    // increment the position and add to map //

    ///////////////////////////////////////////

    position++;

    orderPositionMap[order.orderNo] = position;

    utils.log("orderPositionMap put [" + order.orderNo + "] get [" + position + "]");



    ////////////////////////

    // lookup the carrier //

    ////////////////////////

    var carrierId = orderList.get(i).carrierId;

    if(carrierId && ! carrierMap[carrierId])

    {

        carrierMap[carrierId] = infoplusApi.getById("carrier", carrierId);

        utils.log("Looked up carrier [" + carrierId + "] as [" + carrierMap[carrierId].label + "]");

    }



    ////////////////////

    // lookup the lob //

    ////////////////////

    var lobId = orderList.get(i).lobId;

    if(lobId && ! lobMap[lobId])

    {

        lobMap[lobId] = infoplusApi.getById("lineOfBusiness", lobId);

        utils.log("Looked up LOB [" + lobId + "] as [" + lobMap[lobId].label + "]");

    }



    ///////////////////////////

    // lookup the cartonType //

    ///////////////////////////

    var estimatedCartonPlan = orderList.get(i).estimatedCartonizationPlan.split("\n");

    if (estimatedCartonPlan.length > 0 && ! cartonMap[order.orderNo]) {

        cartonMap[Math.round(order.orderNo)] = {"carton":estimatedCartonPlan[0]};

        utils.log("Looked up carton type for order [" + Math.round(order.orderNo) + "] as [" + cartonMap[Math.round(order.orderNo)].carton + "]");

    }



    var customer = infoplusApi.search("customer", "lobId eq " + lobId + " and customerNo eq '" + order.customerNo + "'", null, null, null);

    if (customer.size() > 0) {

        customerMap[Math.round(order.orderNo)] = {"customer" : customer.get(0).name}

        utils.log("customer for order [" + Math.round(order.orderNo) + "] as [" + customerMap[Math.round(order.orderNo)].customer + "]");

    } else {

        utils.log("Warning!! customer information missing!");

    }

}



///////////////////////

// add to our output //

///////////////////////

output.put("carrierMap", carrierMap);

output.put("lobMap", lobMap);

output.put("orderPositionMap", orderPositionMap);

output.put("cartonMap", cartonMap);

output.put("customerMap", customerMap);




Step 3: Navigate back to the Smart Documents Template Table


  • Find the Smart Document you created in step 1

  • Click Edit on the Smart Document

  • Navigate to the Script drop-down

  • Select the script you created in Step Two

  • Save 



Step 4: Test the Order Assembly Guide Customizations by running a Fulfillment Process and seeing if the customizations you added are performed