Outputting Data Objects From Rule StepsLast Updated: 03/15/2016 Introduced in Verision: 2.0
Rule Steps can be configured to return data objects rather than simple outcomes. For example, you can create a rule that outputs an account object that can then be displayed in a form.
In the Properties panel of the Rule Designer, in the Flow Data section, next to the Flow Input Data box, click the Add button to open a form for defining that rule’s output as the individual type or list of your choosing.
To create a data outcome rather than multiple path outcomes, in the Properties panel, in the Output section, in the Rule Type drop-down list, select Data Return Rule.
Map that output to a form’s input using the Mapping Editor.
Our example flow will display a form that accepts a username and a value for years of experience. Based on the values we submit, our flow will then open a form displaying user information.
Rather than displaying information for every user in the system, our example flow will only display information for two new users. If, in our first form, we enter a value greater than 3 for years of experience, our flow will display information for the new user “Rahul.” If we enter a value less than or equal to three, our flow will display information for the new user “Amol.”
Many of the steps in the flow have been created for this example, including the form in which we enter data, and the form that displays the results.
We’ll begin our flow with many of our steps already in place. Our first step [Form] User Info displays our first form. Parse Number 1 parses the “Years of Experience” value from our first form and ensures that the value is an integer. Get All 1 gets all user accounts from our system.
The last step of our flow [Form] Form 1 will display the details of the user account objects that our missing rule step will output.
To create our rule step, in the Components panel, in the Rule category, we will drag a [Pick Or Create Rule Step] component to the workspace. Once it is placed, we will click the link Pick or Create Rule from the Properties panel.
We will give our rule a name and click OK.
Next, we will build our rule. We’ll begin by defining a data type for the flow input, which sets the type of data that the rule’s conditions will evaluate.
In the Start Rule window, in the Rule Data section, next to the Rule Data Input box, we will click the Add New.
Then, we’ll enter a name for the input, and click the Type selector.
We will select an integer data type (“Int32”) and click OK.
Back in the Edit object pop-up, we save the input data by clicking Save.
To begin adding conditions to the rule, we select Add New Rule Step from the menu.
Since the rule has only one condition, it will be fairly simple to build. In the Text Rule View tab, we will build the condition: “If Exp Greater Than 3”, where “Exp” will be the parsed “Years of Experience” from our first form.
We select Exp [Int32] and click Next.
We expand Number Rules, click Greater Than, and click Next.
Finally, on the Inputs step, with a mapping type of Constant, we enter “3” in the Value field and click Close.
Rule 1, as we’ve created it so far, will now generate two outcome paths “True” or “False” depending on whether the integer it is evaluating is greater than 3 or not.
If we wanted those outcomes to lead to significantly different steps, we might save Rule 1 as it is. However, we want Rule 1 to lead to the same step, just with different data. Our requirements state that the integer entered on a form should be evaluated, and then the resulting form should display an account object.
To create a data outcome rather than multiple path outcomes, in the Properties panel, in the Output section, in the Rule Type drop-down list, we select Data Return Rule.
This reveals controls that we can use to define a data output for our rule. By default, the Output Type is still “Boolean.” We want Rule 1 to output an Account object for display in [Form] Form 1. To do this, we will click the Output Type selector.
The resulting pop-up allows us to navigate through all of the data structures in our system and select the one that’s right for our purpose. We will find Account then click OK.
Next, we need to define the two new user accounts that will be returned, depending on Rule 1’s outcome.
In the Text Rule View, click (Add) to the right from the Return step in Then section. Next, from the Mapping Type drop-down list, we select Constant . . .
. . . then click the Value selector.
We enter an EmailAddress and EntityName and click Save, first entering a new Account object belonging to “Amol”
then one for “Rahul.”
This completes our rule. After we’ve saved it and closed the Rule Designer, we can continue in the Flow Designer.
When we connect the rest of our paths, we’ll notice that Rule 1 has only one outcome path Done rather than the True and False paths we would see for a simple rule. This is the path along which one of the Account objects we created in Rule 1 will pass.
Once our paths are all connected, we will select Rule 1 and click the Show Mapping Editor link in the Properties panel to complete the mappings for Rule 1.
Rule 1 expects the numeric input Exp, which we defined in the Rule Designer. To map it, we will drag and drop the anchor for ParseNumber1_Output to Exp, and click OK to exit the Mapping Editor.
We’ll also want to map the input for [Form] Form 1, so we’ll select it and click the Show Mapping Editor link.
Because we want the form to display details about whichever Account object is outputted by Rule 1, we will map Rule 1 ‘s Result to the first item (Item 0) in the input collection account, then click OK to exit the Mapping Editor.
This completes our flow, so we save it and run it in the Debugger.
Note that in Decisions version 3.5 and above, you’ll need to click on Test Flow to access the Debugger.
We’re presented with a form into which we can enter “Name” and “Years of Experience.” When we enter “4” years of experience
we’re presented with a form containing details of a new user account belonging to Rahul.
We’ll click the Diagram tab to view the flow’s execution.
If we enter a number less than three for “Years of Experience”, such as “1”
we’re presented with a form containing details of a new user account belonging to Amol.