Sequential RuleLast Updated: 08/09/2016 Introduced in Verision: 3.2 |
Sequential Rule was introduced in Decisions 3.2 version. This type of Rule is basically a Flow that represents a sequence of steps that evaluate data. It can be used when the designer wants to embed a complex data evaluation or a sequence of simple rules into a single Rule (Sub Flow). This tutorial demonstrates how to create a Sequential Rule and use it in the Workflow.
Example:
In this example we will create a Sequential Rule that will have a Product Name string as an input, and check if this Product is Out of Stock (based on database query). Then, it will return True or False Boolean value. Next, we will use this Sequential Rule in the Flow to display a list of Products that are Out of Stock.
We begin in the Designer Folder with clicking Create Rule > Create Sequential Rule button on the Folder Actions Panel.
As we mentioned previously, Sequential Rule is a Flow… It can also be created by setting Flow Behavior to Sequential Rule while Creating Flow.
Next, we Name our Sequential Rule and click Create to proceed.
In the Flow Designer we define Flow Inputs first. We select Start Step on the workspace, click Add New Flow Input Data, Name Flow Input and define its type String. Click Ok to save and continue.
When Flow Input Data is defined we can click Add Step to start designing our Flow.
First, we add Create Data step from Favorite Steps category.
In the resulting window we click Add New to define Data. Then, we Name our Data and pick Boolean Type. Click Ok to save.
When Data is defined we click Add.
Next to Create Data step on the workspace we add Get All from dbo.Products step from Integrations > My Integrations > Database > North (Database) > dbo.Products (Table) category (note: this step was generated by the System while External Database integration).
Then, we connect Failed outcome from the Get All from dbo.Products step to the End Step in our Flow. Additionally, we configure to Ignore Limit Count inputs to this step.
Next, we select Create Or Copy (Result) step on the workspace and set our Result variable to be Constantly False. We will change the value of this variable to True later in the Flow if Product is Out of Stock.
On the Done outcome from the Get All from db.Products step we add For Each Element step from the Favorite Steps category.
In the resulting window we pick Products_Result collection and click Add.
Then, on the Next outcome from the For Each Element in our Flow we add [Pick or Create Rule] step from Flows, Rules, Forms and Reports > Rules category.
Next, we Name the Rule and click Create to proceed to the Rule Designer.
In the Rule Designer we click Add New link to add Rule Inputs. Then, we Name input, define its Type and click Ok.
For this Rule we are going to add three inputs: ProductName (String), CurrentProductName (String) and inStockQty (int32). When all inputs added we click Add New Rule Step.
Our Rule will have two Phrases. First, to check if current iteration matches the Product Name that was an input to our Flow. In the Rule Phrase Builder we pick ProductName and click Next.
In the resulting Verb definition window we pick Equals verb from the Text Rules category and click Next.
In the next window of the Rule Phrase Builder we use Select Value Mapping type and with the Path picker select CurrentProductName Rule input.
Click Done when finished.
Next, we click Add New Rule Step button to add the second condition to our Rule.
This Rule Phrase will check if the Quantity of the Product in Stock is Greater than zero. We pick inStockQty and click Next.
In the Verb definition window we select Greater Than verb from Number Rules category and click Next.
Finally, in the last window of the Rule Phrase Builder we define Constant Value ‘0’. Click Done to save and continue.
Our Rule is completed. We can save it and close Rule Designer to continue building our Sequential Rule.
Back in the Flow Designer we connect False outcome from our Rule back to the For Each Element step in the Flow. Then we click Show Mapping Editor for our Rule to configure Input Data.
In the Mapping Editor we map data in the following manner… We connect ProductName Flow Input to the Product Name Rule Input. Then, we expand Item outcome from the For Each Element step and connect ProductName to the CurrentProductName and UntsInStock to the inStockQty input to the Rule. Then, we save and close Mapping Editor.
On the True outcome from the Rule we add another Create Or Copy Data step from the Favorite Steps category.
In the data definition window we Add New Data and define it as Boolean type named ‘True’.
When data is defined we click Add.
We configure data in this Create Or Copy Data step as following… In the Inputs section we set our variable to be Constant with True Value. In the Outputs section we use Change Value Mapping type and with Path picker select Result variable that we created in the first Create Or Copy Data in our Flow. Then, we connect Done outcome from this step to the End Step in our Flow.
Finally, we select End Step in our Flow and configure its Inputs with Select Value Mapping type. With Path picker we select Result value.
This completes our Sequential Rule design. We can save the Flow and close Flow Designer.
Now, we are ready to test our Sequential Rule in the Flow. In the Designer Folder we click Create Flow on the Folder Actions Panel.
Then, we Name the Flow and click Create to proceed.
In the Flow Designer we add Create Or Copy Data step from the Favorite Steps category.
In this Create Or Copy data step we define our Data as a List of Strings that Can Be Null. Click Ok to save and continue.
When our List is defined we click Add.
Next to the Create Or Copy Data step we add Get all from dbo.Products step from the Integrations > My Integrations > Database > North (Database) > dbo.Products (Table) category.
Then, we connect Failed outcome from Get all from dbo.Products step to the End Step in the Flow and configure to Ignore Limit count Inputs to this step.
On the Done outcome from the Get all from dbo.Products step we add For Each Element step from the Favorite Steps category.
Next, we pick Products_Result as a collection for For Each Element step and click Add.
On the Next outcome from the For Each Element step we add our isProductInStock Sequential Rule from the Flows, Rules, Forms and Reports > Flows > [Current Folder] category.
We configure Inputs into our Sequential Rule step using Select Value Mapping type and picking ProductName value from Item outcome from the For Each Element step.
At this point our Sequential Rule has one Outcome. To make it have True and False outcomes we expand Outcomes section and check Expose Step as a Rule checkbox.
Then, we connect True outcome from the Sequential Rule step back to the For Each Element step and on the False outcome we add Add Item to List step from the All Steps [Catalog] > Data > List category.
Next, we select Add Item to List step and click Show Mapping Editor action.
In the Mapping Editor on the left-hand side we expand Item outcome from the For Each Element step and connect ProductName to the New Item field. Then, we use listOfOutOfStockProducts that we created in the Create Or Copy Data step in this Flow as an Original List input. On the right-hand side of the Mapping Editor we Change Value of the listOfOutOfStockProducts with the outcome from this step. Save and close Mapping Editor.
In the Flow Designer we connect Done outcome from the Add Item to List step back to the For Each Element step. On the Done outcome from the For Each Element step we add Show Form step from the Favorite Steps category.
In the resulting window we Name the Form and click Create to proceed to the Form Designer.
Our Form is designed simply to display a List of Product Names… When we finished designing the Form we can save and close Form Designer.
Back in the Flow Designer we connect Done outcome from the Form step to the End Step in the Flow. Then, we select our Form step and for the ListOfProducts Input we Select Value of the listOfOutOfStockProducts.
This completes our Flow Design. We can click Debug Flow link on the top panel of the Flow Designer to test our Flow.
Note that in Decisions version 3.5 and above, you’ll need to click Test Flow to access the Debugger.
Our Form opens in the Debugger with the Simple List that displays all Out Of Stock Product Names. We click Done to close the Form and terminate our Flow Execution.
Debugger Diagram indicates that our Flow ran to the End Step with no issues.