List Container RulesLast Updated: 07/15/2016 Introduced in Verision: 2.0
List Container Rules implemented in Decisions 3.2.0 in Rule Engine. These Rules are designed to process a list of items and apply desirable conditions to each item in the list. List Container Rules have following options: Contains All, Contains Any, and Does Not Contain Any.
- Contains All – each item in the list should satisfy condition for Rule to evaluate as True.
- Contains Any – at least one item in the list should satisfy condition for Rule to evaluate as True.
- Does Not Contain Any – none of the items in the list should satisfy the condition for Rule to evaluate as True.
In this example we are going to create a Rule that takes in an array of Accounts. It should evaluate as True if all Accounts in the array have Email Address that contains “decisions”. We are going to use List Container Rules to test each Account in the array.
We begin in the Designer Folder with clicking Create Rule > Create Rule option on the Folder Actions Panel.
In the resulting window we Name our Rule and click Create to proceed to the Rule Designer.
In the Rule Designer we click Add New link to add Rule Input Data.
Next, in the Add Rule Input Data window we Name our Input (Accounts), use Type Picker to define Account Type, and check Is List checkbox to make it an array. Then, we click Ok to save and close this pop-up window.
Back in the Start Rule window we click Add New Rule Step to start building our Rule.
In the resulting window we pick our array of Accounts and click Next.
In the next window we should be able to see List Container Rules category because Accounts variable is an array. We click Contains All option from the List Container Rules category because we want to check if all Emails contain “decisions”. Then, we click Next.
In the resulting window we provide a Name for the Element in the array and click Done.
Our List Container Rule phrase is completed and we can click Close in the resulting window.
Then, we click (Add) link that is related to our List Container Rule and select Add Condition option. Here, we are going to create Conditions that each item in the list should pass. In this case we are going to check if Account.EmailAddress contains “decisions”.
In the resulting window we expand Account category (which is the Name for each element in the Array) and select EmailAddress field. Then, we click Next.
In the following window we select Contains verb from the Text Rules category and click Next.
In the last window of the Rule Phrase Builder we set Mapping Type Constant with Value “decisions”. Click Done when finished.
Our Rule is completed. We click Close to close Rule Phrase Editor.
To test our Rule we click Debug Rule on the top panel of the Rule Designer.
*Note In Decisions 3.5 Debug Rule is renamed Test Rule
Next, we are going to create two Unit Tests for our Rule. We name our first Unit Test Pass, leave Test Result to Pass and click Add New link to add accounts to our Rule Input.
In the resulting window we simply pick account from the list of existing accounts and click Pick.
Mention, that for this Unit Test we picked only accounts that contain “decisions” in their Email Address. Click Save to save this Unit Test.
Next, in the resulting window we click Create New link to add second Unit Test. We create this Unit Test in the similar manner as previous except this time we set Test Result to Fail and intentionally add an Account with an Email Address that does not contain “decisions”. In this case Rule should evaluate as False and we expect Unit Test to Fail. Click Save to save second Unit Test.
Next, we click Run All button to run both Unit Tests at the same time.
As we expected, our first Unit Test Passes and second Unit Test Fails.