Previously, for ASN and Order record types, Smart Documents and Barcode Templates could only produce one document per record.  This article explains how to produce a Smart Document or Barcode Template for an ASN/Order Line or an ASN/Order Line Each.


Configuring a Smart Document or Barcode Template


When creating a Smart Document or Barcode Template, if the Record Type chosen is Order or ASN, a new dropdown is presented called Record Subtype.  This new dropdown defines if the template is produced at the Line Item level or Each level.  The Record Subtype field is optional and if left blank, the template will be rendered for a single record, like all other record types.



Orders


For Orders, if Line Item is selected as the Record Subtype, a document or barcode will be rendered for each Order Line.  For this Record Subtype, following data is available for use in the templates:


$record - The Order Line API object

$recordCount - The count of what Order Line is being rendered

$totalCount - The total number of Order Lines

$parentRecord - The Order API object for the Order Lines

$barcodes - Utility object for generating barcodes (Defaults to Code 128B)

$barcodesUPCA - Utility object for generating UPC-A barcodes.

$barcodes128B - Utility object for generating Code 128B barcodes.

$scriptOutput - Data set for use by the template from an associated script. (Smart Document Templates only)


Here's an example of an Order Smart Document Template with a Record Subtype of Line Item:


<p>
Line Item Id: $record.sku<br />
Order No: $parentRecord.orderNo<br />
<strong>$recordCount</strong> of <strong>$totalCount</strong><br />
Barcode: <img src="$barcodes.sku" alt="" width="300" height="100" /><br />
UPCA: <img src="$barcodesUPCA.vendorSKU" alt="" width="300" height="100" /><br />
Code 128B: <img src="$barcodes128B.sku" alt="" width="300" height="100" />
</p>


For Orders, if Each is selected as the Record Subtype, a document or barcode will be rendered for each "Each".  For this Record Subtype, the following data is available for use in the template:


$record - The Item API object

$recordCount - The count of what Each is being rendered

$totalCount - The total number of Eaches

$parentRecord - The Order Line API object for the Each

$barcodes - Utility object for generating barcodes (Defaults to Code 128B)

$barcodesUPCA - Utility object for generating UPC-A barcodes.

$barcodes128B - Utility object for generating Code 128B barcodes.

$scriptOutput - Data set for use by the template from an associated script. (Smart Document Templates only)


Here's an example of an Order Smart Document Template with a Record Subtype of Each:


<p>
SKU: $record.sku<br />
Line Item Id: $parentRecord.id<br />
<strong>$recordCount</strong> of <strong>$totalCount</strong><br />
Barcode: <img src="$barcodes.sku" alt="" width="300" height="100" /><br />
UPCA: <img src="$barcodesUPCA.vendorSKU" alt="" width="300" height="100" /><br />
Code 128B: <img src="$barcodes128B.sku" alt="" width="300" height="100" />
</p>


ASNs


For ASNs, if Line Item is selected as the Record Subtype, a document or barcode will be rendered for each Item Receipt.  For this Record Subtype, following data is available for use in the templates:


$record - The Item Receipt API object

$recordCount - The count of what Item Receipt is being rendered

$totalCount - The total number of Item Receipts

$parentRecord - The ASN API object for the Item Receipt

$barcodes - Utility object for generating barcodes (Defaults to Code 128B)

$barcodesUPCA - Utility object for generating UPC-A barcodes.

$barcodes128B - Utility object for generating Code 128B barcodes.

$scriptOutput - Data set for use by the template from an associated script. (Smart Document Templates only)


Here's an example of an ASN Smart Document Template with a Record Subtype of Line Item:


<p>
Item Receipt Id: $record.id<br />
PO No: $parentRecord.poNo<br />
<strong>$recordCount</strong> of <strong>$totalCount</strong><br />
Barcode: <img src="$barcodes.sku" alt="" width="300" height="100" /><br />
UPCA: <img src="$barcodesUPCA.vendorSKU" alt="" width="300" height="100" /><br />
Code 128B: <img src="$barcodes128B.sku" alt="" width="300" height="100" />
</p>


For ASNs, if Each is selected as the Record Subtype, a document or barcode will be rendered for each "Each".   For this Record Subtype, following data is available for use in the templates:


$record - The Item API object

$recordCount - The count of what Each is being rendered

$totalCount - The total number of Eaches

$parentRecord - The Item Receipt API object for the Each

$barcodes - Utility object for generating barcodes (Defaults to Code 128B)

$barcodesUPCA - Utility object for generating UPC-A barcodes.

$barcodes128B - Utility object for generating Code 128B barcodes.

$scriptOutput - Data set for use by the template from an associated script. (Smart Document Templates only)


Here's an example of an ASN Smart Document Template with a Record Subtype of Each:


<p>
SKU: $record.sku<br />
Item Receipt Id: $parentRecord.id<br />
<strong>$recordCount</strong> of <strong>$totalCount</strong><br />
Barcode: <img src="$barcodes.sku" alt="" width="300" height="100" /><br />
UPCA: <img src="$barcodesUPCA.vendorSKU" alt="" width="300" height="100" /><br />
Code 128B: <img src="$barcodes128B.sku" alt="" width="300" height="100" />
</p>


Using Scripts 


Additional extra data is made available to scripts if a Record Subtype is selected in a Smart Document Template.  In addition to the information already available in Smart Document Template scripts, the following data is also available:


Orders


For Order with a Record Subtype of Order Line:


order - The Order API object

orderLineList - The list of Line Item API objects


For Order with a Record Subtype of Order Line:


order - The Order API object

orderLineList - The list of Line Item API objects

itemMap - a map of all Item API objects on the order where SKU is the key



ASNs


For ASN with a Record Subtype of Order Line:


asn - The ASN API object

lineItems - The list of Item Receipt API objects


For ASN with a Record Subtype of Each:


asn - The ASN API object

lineItems - the list of Item Receipt API objects\

itemMap - a map of all Item API objects on the ASN where the SKU is the key


Here's an example Order Smart Document Template Script for the Order Line use case:


// Example of accessing extra data for Order record with 'Each' subtype:
utils.log("Order No: " + order.orderNo);
utils.log("Total Line Items: " + orderLineList.size());
 
// iterate over lines in order printing the sku and quantity
for(var i=0; i<orderLineList.size(); i++)
{
   var orderLine = orderLineList.get(i);
   var item = itemMap.get(orderLine.sku);
    
   utils.log("Line Item Count: " + orderLineList.size());
   utils.log("SKU: " + item.sku);
   utils.log("Vendor SKU: " + item.vendorSKU);
}
 
// putting data into object for Smart Document Template
output.put("itemMap", itemMap);



A note about using the && operator in Smart Documents


If you're having issues using the && operator in Smart Document templates, try putting them inside an HTML comment, like so:


<!-- #if($var1 && $var2) --> 
<div>test<div/>
<!-- #end -->