Here are some real-world examples of solutions that have been built in Infoplus using Scripts.  For more examples see the articles written under our Scripts bridge page


Automatically place Orders on Hold

Use Case:  You want to place a Hold on any Order that is placed meeting certain conditions (such as, for a total value over some amount, or for a specific line item, or with a special ship-to destination).  


This script could be assigned to run with a Trigger that searched for new Orders containing the Item "SOURCE".

order.holdCode = "H";
 
// explicitly clear these values, to avoid "not modifyable" error
order.extraLineItemData = null;
order.extraOrderData = null;
 
utils.log("Will try to set order " + order.orderNo + " hold code to H...");
infoplusApi.update("order", order);
utils.log("Set order " + order.orderNo + " hold code to H");


Update the names of all Third Party Parcel Accounts to match their Account Numbers

Use Case:  To clean up the data in your Third Party Parcel Account table, you want to update all records so that their Account Names match their Account Numbers.  


This can be done by creating a simple script like this, then selecting rows from the Third Party Parcel Accounts table and using the Bulk Run Script process.

thirdPartyParcelAccount.accountName = thirdPartyParcelAccount.accountNo;
utils.log("Updating thirdPartyParcelAccount [" + thirdPartyParcelAccount.id + "] to have name [" + thirdPartyParcelAccount.accountName + "].");
infoplusApi.update("thirdPartyParcelAccount", thirdPartyParcelAccount);


Split an Order into Two Orders

Use Case:  Any time an Order is placed for the Item "SOURCE", a second order should be created, with the same root order number, for the Item "TARGET".


This script could be assigned to run with a Trigger that searched for new Orders containing the Item "SOURCE".

var SOURCE_SKU = "SOURCE";
var TARGET_SKU = "TARGET";

var sourceLineItem = null;
if(order.lineItems)
{
   for(var i=0; i<order.lineItems.size(); i++)
   {
      if(order.lineItems.get(i).sku == SOURCE_SKU)
      {
         sourceLineItem = order.lineItems.get(i);
         break;
      }
   }
}

if(sourceLineItem == null)
{
   utils.log("Did not find source sku [" + SOURCE_SKU + "] on order.  Exiting.");
   return;
}

var blankOrder = infoplusApi.constructModel("order");
var newOrder = infoplusApi.duplicate("order", order.orderNo);
newOrder.lineItems = blankOrder.lineItems;

var newLineItem = infoplusApi.duplicate("orderLine", sourceLineItem.id);
newLineItem.sku = TARGET_SKU;
newLineItem.orderedQty = sourceLineItem.orderedQty;

newOrder.addToLineItems(newLineItem);
newOrder.useOrderNoRoot = Math.floor(order.orderNo);
newOrder.holdCode = null;
newOrder.carrierId = 0;
newOrder.needByDate = null;
newOrder.deliverOnDate = null;
newOrder.shipVia = null;

var addedOrder = infoplusApi.add("order", newOrder);
utils.log("Created order [" + addedOrder.orderNo + "] with SKU [" + TARGET_SKU + "].");


Change an Order containing Items set as Hazmat to land on hold with a Tag

Use Case: When an Order lands for an Item set up as Hazmat, place the Order on hold and add a tag to it.

if(order.lineItems)
{
   var targetHoldCode = "H";
   if(order.holdCode.equals(targetHoldCode))
   {
      utils.log("Order already has holdCode " + targetHoldCode);
   }
   else
   {
      ///////////////////////////////////////////////////
      // setup a filter for all the items on the order //
      ///////////////////////////////////////////////////
      var itemFilter = "lobId eq " + order.lobId + " and sku in (";

      for(var i = 0; i < order.lineItems.size(); i++)
      {
         var lineItem = order.lineItems.get(i);
         itemFilter += (i > 0 ? "," : "") + "'" + lineItem.sku + "'";
      }
      itemFilter += ")";

      var orderContainsHazmat = false;
      var items = infoplusApi.search("item", itemFilter, null, 100, null);

      if(items.size() > 0)
      {
         /////////////////////////////////////////////////////////
         // iterate over item list looking for any hazmat items //
         /////////////////////////////////////////////////////////
         for(var i = 0; i < items.size(); i++)
         {
            var item = items.get(i);
            if(item.hazmat.equals("Yes"))
            {
               utils.log("Found Hazmat sku " + item.sku + " or order");
               orderContainsHazmat = true;
               break;
            }
         }
      }
      else
      {
         utils.log("No items found from order line items");
      }

      if(orderContainsHazmat)
      {
         ////////////////////////////////////////////////////////////////////
         // explicitly clear these values, to avoid "not modifyable" error //
         ////////////////////////////////////////////////////////////////////
         order.extraLineItemData = null;
         order.extraOrderData = null;

         ////////////////////////////
         // add a tag to the order //
         ////////////////////////////
         infoplusApi.addTag("order", order.orderNo, "hazmat-shipment");

         //////////////////////////////////
         // put a hold code on the order //
         //////////////////////////////////
         order.holdCode = targetHoldCode;

         utils.log("setting order hold on " + order.orderNo + " found hazmat items");
         infoplusApi.update("order", order);
      }
   }
}