TABLE OF CONTENTS


Intro


In this article will be covered an example of data notification, returning the parent record and all the related children records (of selected children entities) whenever either the parent record or one of the children record is updated. 


For the purpose of this article a model with three entities will be used, as follow :

  1. Customer : a fuzzy-matched entity containing all the information about the customers of this fictive company (name, address, ...)
  2. Product : a basic entity containing all the information about the products this fictive company has to sell (name, price, ...)
  3. CustomerProduct : a basic entity linking the 2 other entities, providing as well some information about the purchase (FK customer, FK product, date of purchase, ...)


Create the named query


A data notification will, when triggered, return the content of a named query. Thus the first step is to create such named query. To understand how named queries work and how to create them, please refer to the xDM documentation.

For this example, the named query will return information about the customer, and the related products that customer bought. Therefore the named query looks like this.



In the 'Object Properties' panel is registered all the information that the query will return, as described earlier. One can notice that this query has been optimized to link directly Customer and Product, with only implicitly mentioning CustomerProduct. This is not mandatory, be will allow the named query to run faster (you can learn more about named query optimization in this article)


In the 'Name and Definition' panel is configured the filter. In this example the named query is filtered in a way that any parent record that either has been changed or has at least one child that has been changed between the two batches will be returned. Here is the generic syntax for this kind of filter.

BatchID > :QUERY_PARAM_PRIOR_BATCH AND BatchID <= :QUERY_PARAM_TO_BATCH
OR ANY ChildEntities1 HAVE (BatchID > :QUERY_PARAM_PRIOR_BATCH AND BatchID <= :QUERY_PARAM_TO_BATCH)
OR ANY ChildEntities2 HAVE (BatchID > :QUERY_PARAM_PRIOR_BATCH AND BatchID <= :QUERY_PARAM_TO_BATCH)
OR ANY ChildEntities3 HAVE (BatchID > :QUERY_PARAM_PRIOR_BATCH AND BatchID <= :QUERY_PARAM_TO_BATCH)

Remember to check that the query is marked as 'active' in the Name and Definition panel.




Create the data notification


Now that the named query is complete, the next step is to create the data notification that will use it. To do so you can follow the instructions from the documentation, this article will only cover the watched entities.


The Watched Entities property allows the data notification to trigger only when the selected entities have been modified, instead of the default option which is to trigger when any entity is modified. Selecting watched entities is important to reduce the resources consumed by data notifications.

In this example case, both Customer and CustomerProduct entities have been selected as watched entities, which means whenever a customer is updated (new customer, or modification of an existing customer basic information), or whenever a command is update (a customer buy new articles, or a previous command is modified) the data notification will trigger, but it will not trigger if the entity Product is modified (a product is renamed, a product's price is adjusted, ...).


Remember to save and activate the data notification before closing it, otherwise it won't trigger.



End of document.