Due to the ever-changing nature of writing and maintaining scripts, Infoplus does not provide support in this area. We recommend someone in your IT Department handles scripting requests internally so that you keep all control over the process.

This example script shows how dynamic kits can be added to an order.  The script has 2 example use cases:

  1. First, if a line item is found on the order for the SKU "BASIC7", that line item is converted to a Dynamic Kit for 2 component items:  BASIC8 and BASIC9.
  2. Second, if the order's ship-to state is Missouri (MO), a new line item is added to the order, for BASIC5, and this new line item is a Dynamic kit for 3 SKUs. 


The function addDynamicKitComponentToLineItem at the top of the script can be copied as-is into your own script.  You can then add your own custom business rules to use this function for adding Dynamic Kits to your orders.  


////////////////////////////////////////////////////////////
// function to add a dynamic-kit-component to a line-item //
////////////////////////////////////////////////////////////
function addDynamicKitComponentToLineItem(lineItem, componentSku, componentQuantityPerKit)
{
    var dynamicKitComponentLine = infoplusApi.constructModel("dynamicKitComponentLine");
    dynamicKitComponentLine.lobId = lineItem.lobId;
    dynamicKitComponentLine.sku = componentSku;
    dynamicKitComponentLine.perKitQuantity = componentQuantityPerKit;
    lineItem.addToDynamicKitComponentList(dynamicKitComponentLine);
}



////////////////////////////////////////////////////////////////
// Business Rule #1:                                          //
// if the order has a line item for SKU:  BASIC7, then        //
// make that line a dynamic-kit, for SKU's BASIC8 and BASIC9. //
////////////////////////////////////////////////////////////////
var needUpdate = false;
for(var i=0; i<record.lineItems.size(); i++)
{
    var lineItem = record.lineItems.get(i);
    if(lineItem.sku == "BASIC7")
    {
        utils.log("Found line item to convert to Dyanmic Kit");
        needUpdate = true;
        addDynamicKitComponentToLineItem(lineItem, "BASIC8", 2);
        addDynamicKitComponentToLineItem(lineItem, "BASIC9", 3);
    }
}

//////////////////////////////////////////////////////////////////////////
// Business Rule #2:                                                    //
// if the order is shipping to the state of MO, add a dynamic kit to it //
//////////////////////////////////////////////////////////////////////////
if(record.shipToState == "MO")
{
    utils.log("Found MO order - adding dynamic kit");
    needUpdate = true;

    var newLineItem = infoplusApi.constructModel("orderLine");
    record.addToLineItems(newLineItem);
    
    newLineItem.lobId = record.lobId;
    newLineItem.sku = "BASIC5";
    newLineItem.orderedQty = 5;
    
    addDynamicKitComponentToLineItem(newLineItem, "BASIC4", 3);
    addDynamicKitComponentToLineItem(newLineItem, "BASIC3", 2);
    addDynamicKitComponentToLineItem(newLineItem, "BASIC2", 1);
}

///////////////////////////////////////////
// if the order needs updated, do so now //
///////////////////////////////////////////
if(needUpdate)
{
    utils.log("Updating order");
    infoplusApi.update("order", record);
    utils.log("Updated successfully.");
}
else
{
    utils.log("No update needed.");
}