Infoplus Scripts can be used to allow you to customize the behavior of your EDI Connections. For each Document Type, Infoplus has a built-in translation or mapping that it uses, based on configurations specified in the EDI Connection. However, to support custom business rules or features that aren't available in the core of Infoplus, a script can optionally be used to modify both Inbound and Outbound documents.


All Document Types have some common objects available in the global script context. These include:

  • utils
  • infoplusApi
  • documentModel (JSON representation of incoming EDI)
  • ediUtils
  • inboundDocumentModel (JSON representation of inbound EDI (855, 856))
  • parcelShipmentList (list of parcelShipment API objects (856))


Inbound 850 Example

  • order - this object is an instance of the Infoplus API's order type.  It will be initially populated with the default mapping that Infoplus has performed on the 850.  You can modify this object to customize this mapping.  For example, to change the carrier used when the order is created, you would say "order.carrierId = 0;" Consult the Infoplus API Documentation for full details on fields available on this object.
  • documentModel - this object is a representation of an SPS Commerce RSX Order document. You can read values from this object, to apply logic for how you want to customize the order object.  For example, to see the carrier that was specified in the 850 document, you would say "documentModel.getHeader().getCarrierInformation().get(0).getCarrierAlphaCode()".


To combine the two concepts introduced above, we could imagine:

var carrierFrom850 = documentModel.getHeader().getCarrierInformation().get(0).getCarrierAlphaCode();
utils.log("Read carrier [" + carrierFrom850 + "] from 850 document carrierAlphaCode");

if(carrierFrom850 == "UPGF")
{
   order.carrierId = 7000;
}
else if(carrierFrom850 == "UP1D")
{
   order.carrierId = 1;
}
else if(carrierFrom850 == "UP2D")
{
   order.carrierId = 2;
}
else
{
   utils.log("Using default carrier 111 because carrier from 850 was not recognized.");
   order.carrierId = 111;
}



Methods and Examples:


MethodPurposeInputsExamples
getNumberPadded


getDateFormatted


getElementValueBySegmentAndElementRef
getSegmentArrayBySegment



getElementValueBySegmentAndElementRefForQualifier

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

// Get the REF segment with the Qualifier "T1" and set it to the Parcel Label Ref 1 //

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

var ediParcelLabelRef1 = ediUtils.getElementValueBySegmentAndElementRefForQualifier(documentModel, "REF""T1", 2);

utils.log("Updating Infoplus Order with ediParcelLabelRef1[" + ediParcelLabelRef1 + "]");

order.parcelLabelRef1 = ediParcelLabelRef1;


getIntegerElementValueBySegmentAndElementRefForQualifier


getN1AddressLoopArrayByIdentificationQualifier

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

// Get the N1 Address loop for Qualifier ST (Ship To)                           //

// then get the N3 Segments 03 Element (Street 3) and set it as Orders Street 2 //

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

var shipToArray = ediUtils.getN1AddressLoopArrayByIdentificationQualifier(documentModel,"ST");

var ediStreet3 = ediUtils.getElementValueBySegmentAndElementRef(shipToArray, "N3", 3);

utils.log("Found street3 value from inbound EDI as[" + ediStreet3 + "]");

order.shipToStreet2 = ediStreet3;

order.shipToStreet3 = "-EDI Script 1";


getPO1ItemDataLoopArray


rejectDocument



Script Examples:

Test Script (multiple examples of getting values from EDI document):

utils.log("Running EDI 850 script for order with CustomerPoNo: " + order.customerPoNo);
 
////////////////////////////////////////////////////////
// Set a order value, just hardcoded in script no EDI //
////////////////////////////////////////////////////////
var customerOrderNo = "SCRIPT-UPDATED-ORDER-NO";
utils.log("Updating Infoplus Order with Customer Order No=[" + customerOrderNo + "]");
order.customerOrderNo = customerOrderNo;
 
//////////////////////////////
// output our documentModel //
//////////////////////////////
// utils.log("documentModel: " + documentModel);
 
//////////////////////////////////////////////////////////////////////////////////////
// Get the REF segment with the Qualifier "T1" and set it to the Parcel Label Ref 1 //
//////////////////////////////////////////////////////////////////////////////////////
var ediParcelLabelRef1 = ediUtils.getElementValueBySegmentAndElementRefForQualifier(documentModel, "REF", "T1", 2);
utils.log("Updating Infoplus Order with ediParcelLabelRef1[" + ediParcelLabelRef1 + "]");
order.parcelLabelRef1 = ediParcelLabelRef1;
 
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Get the REF segment with the Qualifier "C1" and set its value as the orders "rank" custom field //
/////////////////////////////////////////////////////////////////////////////////////////////////////
var customRank = ediUtils.getElementValueBySegmentAndElementRefForQualifier(documentModel, "REF", "C1", 2);
utils.log("Updating Infoplus Order with custom field rank[" + customRank + "]");
order.customFields.put("rank", customRank);
 
//////////////////////////////////////////////////////////////////////////////////
// Get the N1 Address loop for Qualifier ST (Ship To)                           //
// then get the N3 Segments 03 Element (Street 3) and set it as Orders Street 2 //
//////////////////////////////////////////////////////////////////////////////////
var shipToArray = ediUtils.getN1AddressLoopArrayByIdentificationQualifier(documentModel,"ST");
var ediStreet3 = ediUtils.getElementValueBySegmentAndElementRef(shipToArray, "N3", 3);
utils.log("Found street3 value from inbound EDI as[" + ediStreet3 + "]");
order.shipToStreet2 = ediStreet3;
order.shipToStreet3 = "-EDI Script 1";
 
utils.log("Done");


Test Reject Order (Shows how to reject an EDI Order via Script):

utils.log("Running EDI 850 script for order with CustomerPoNo: " + order.customerPoNo);
 
 <span class="fr-marker" data-id="0" data-type="false" style="display: none; line-height: 0;"></span><span class="fr-marker" data-id="0" data-type="true" style="display: none; line-height: 0;"></span>
//////////////////////////////
// output our documentModel //
//////////////////////////////
// utils.log("documentModel: " + documentModel);
 
/////////////////////////////////////////////////////////////////////////////////
// Get the REF segment with the Qualifier "T1" and use it was reason to reject //
/////////////////////////////////////////////////////////////////////////////////
var testValue = ediUtils.getElementValueBySegmentAndElementRefForQualifier(documentModel, "REF", "T1", 2);
 
if(testValue != null)
{
   utils.log("Reject order due to testValue[" + testValue + "]");
   ediUtils.rejectDocument("It has invalid value of : " + testValue);
}
 
utils.log("Done");