Event-Based Example Leaf Products with Inherited Data

Problem: You only want to publish the leaf product level to a downstream system and the leaves inherit data from ancestors, so events will not be generated for the leaves when inherited data changes.

Solution: When values are inherited from the parent or grandparent level, use Event Filters and Event Generators in an event-based OIEP to ensure that:

  • events generated for the parent or grandparent level are discarded
  • derived events are generated for all descendant leaf level objects that exist in Approved mode (have been published earlier)

Important: The following scripts are only an example and should not be used as-is without thorough testing.

Using the following object types:

Use the following triggering object types setup:

No filters or generators are used for Sales Items, so events generated for this object type always get registered in the queue.

Use the following logic for the grandparent and parent levels (Level 3 and Sales Item Family):

Event Filter - No Events are registered for objects of these object types, but we still need to catch them to be able to generate derived events for descendant Sales Items. The event filter should be a JavaScript business condition that always evaluates to false, as shown below:

Event Generator - The business action for event generation is a little more complex and uses the following binds (logger is optional):

Notice the 'Event Type' bind to a derived event named 'salesItemRepublish.' This is the event that will be generated for descendant Sales Items and it must be defined in advance via the 'Derived Events' node in System Setup.

Important: The following script is only an example and should not be used as-is without thorough testing.

The script to generate derived events for approved Sales Items could look as follows:

Copy
function prodIsInApp(prodID) {
    var appProd;
    manager.executeInWorkspace("Approved", function(appManager) {
        appProd = appManager.getProductHome().getProductByID(prodID);
    });
    return (appProd != null);
}
 
function generateEventForApprovedLeafSalesItems(ancestor) {
    var children = ancestor.getChildren();
    for (var i = 0; i < children.size(); i++) {
        var current = children.get(i);
        if (current.getObjectType().getID() == "SalesItem") {
            if (prodIsInApp(current.getID())) {
                logger.info("Generating 'salesItemRepublish' event for approved descendant Sales Item '" + current.getID() + ".'");
                currentEventQueue.queueDerivedEvent(salesItemRepublish, current);
            }
        }
        else generateEventForApprovedLeafSalesItems(current);
   }
}
 
generateEventForApprovedLeafSalesItems(currentObject);   

The script uses as recursive function 'generateEventForApprovedLeafSalesItems' to find descendent Sales items that are in the Approved workspace.

Output Template - Using the configuration described above, you will need an output template for Sales Items and the different types of possible events. This can be one or multiple lines dependent on the need for different messages for the different events.