A couple years ago I wrote a blog post that highlighted an excellent irAuthor method which adds a member to a collection of messages in a ruleset using a Vocabulary template. While that blog post and that pattern is highly useful even to this day, I came across a limitation in that technique recently which prompts an improvement. The problem? It’s not possible to use that vocabulary template at all entity levels in irAuthor.
Now it IS possible to add a universal add collection member vocabulary template at the application level (signified by the blue A from the Add Vocabulary option). But what if you’re interested in more flexibility in your output than just an add collection member template? Perhaps you’d also like to fire a notification as part of the output actions.
The New Pattern: the Case for an Independent (Rule Set)
In order to create an execute rule set vocabulary template that works at all levels (entity contexts) of a rule application, that vocabulary template needs to be created at the application level (and the rule set needs to be in an independent context). This new pattern variation is similar to the old pattern, but there are a few key differences. These differences have been highlighted in blue below. I’ve also included some relevant screen shots for reference.
- Create an entity (ex: “Error”) to contain the output messages with any desired output fields
- Create a collection of that entity off of the top-level entity (ex: “Errors”). Here’s a sample data structure to represent this:
- Create an explicit rule set in an independent rule set context (ex: “AddOutputMessage”) which contains parameters
- Add a parameter to that rule set of the name and data type of the top-level entity:
- Inside of the AddOutputMessage rule set, add an Add Collection Member rule that uses those parameters as inputs to the Errors collection
- Also: add any other rules that you’d like to have executed when this rule set runs (ex: a fire notification)
- Create a vocabulary template at the application level context which executes that AddOutputMessage rule set; ensure that the top-level entity parameter is completed by entering the top-level entity’s name in the parameters box
That should do it! Let us know if you have any trouble getting this pattern to work, or if you have questions. Best of luck!