Bill of Materials Kit Explosion Example

This is a very complex example: a recursive deep copy, using reactive logic.

For more information:

Requirement

When a kit (Product consisting of other component products) is ordered, we must reduce the quantity of all the components parts, recursively. So, ordering a Boing 747 reduces the bolts quantities repeatedly, for the fuselage, wings, and so forth. 

The following image illustrates the database structure:

Solution

While described here as a separate topic, the Bill of Materials Kit Explosion example is a requirement within Place Order. When ordering a Product that is a kit (that is, composed of other Parts, such as a plane with Wings), you want to reduce inventory for each of the components of the kit. 

The following image shows the solution on the Manage, Rules, By Topic tab:

The key requirement is to populate the SubItems for a kit-based Lineitem, by copying the ProductBillofMaterials to the subItems. You can do this with the following explodeBillofMaterials event rule on Lineitem:

if (logicContext.verb == "INSERT" && row.product.count_components > 0) {
     SysLogic.insertChildrenFrom("lineitems", row.product.components, logicContext);
}

The remaining logic (four rules) is to properly arrange for quantities (that is, if you buy two planes, you need eight engines). SubItems are a child of LineItem objects, representing the bill of materials explosion. The solution is to use the Insert Into From rule extension: see the first action rule in the following image. The qtyOrdered rule computes computes the item quantity for kits (for non-kits, it returns/defaults the entered value).

The solution requires four rules. The following image shows the complete event definition on the Manage, Rules, Event page:

This even definition recursively creates the sub-items from each item. The complete definition of quantity_ordered is a good illustration of conditional logic, depending on whether the lineitem is a sub-item.

Explore the Bill of Materials Kit Explosion

You can use the REST Lab to POST the following to a URL such as:

http://.../APICreator/rest/demo/sample/v1/cust.orders_c

{
   "customer":"Alpha and Sons",
   "IsReady":false,
   "items_o":[
      {
         "ProductName":"Boing 747",
         "QuantityOrdered":2
      }
   ]
}