Using a Rule to Return Data

Last Updated: 08/09/2016 Introduced in Verision: 2.0

Rules evaluate a data input and typically return an outcome of true or false, depending on whether the input satisfies the rule’s conditions. Rules can also output data objects instead of a simple true or false value, depending on whether the rule is satisfied.

To make a rule output data instead of a simple true or false value, create your rule in the Rule Designer. Under the section Output, choose the Rule Type: Data Return Rule and click Add New Rule Step. A new Then Return, Else Return section will appear, containing two mappable properties – Outcome Data [True] and Outcome Data [False]. Use these properties to define the data objects to be returned in either case.

Example

Our example flow will use a rule to determine whether a given user is the Administrator. If the user provides the flow with an email that does not appear in the email address of the user running the flow, it will display a message stating that it is not an admin account. If the user provides the flow with an email address that appears in the email address of the user running the flow, it will display a message stating that it is an admin account.

This example assumes that the runner of the flow is always an Administrator –

Navigate to your Designer Project folder. From the Create Rule button, select Create Rule.

create rule

 

Give the new rule a name, “CheckEmailID” for example, and click OK.

In the Rule Designer, under the Rule Data section, click the Add New button.

Fill in the Name field with “EmailID”, make sure the Type is String and click OK to save.

 2015-02-27_11-53-112015-02-27_11-53-11EmailID

Under the Output section, choose the Rule Type: Data Return Rule.

Click the Output Type selector and in the Pick Type popup, select String.

Because we only want to output one message, not several, leave the Is List checkbox cleared and click OK.

Click Add New Rule Step.

 startrule

Because we want to evaluate the email address of the user running the flow against an email address that the user will input at runtime, select Flow Data [RuleConstantData] > InitializingUserEmail for the anchor variable and click Next.

flowdata

Because we want to test whether the user’s email address contains the email address offered as an input, select Text Rules > Contains for the comparison operator and click Next.
 
For the comparison value, select the flow data input defined earlier by selecting Select Value in the Mapping type drop-down list and clicking the Path selector.

Select EmailID and click OK.

 SelectValue

Click Done to complete the Rule Step and close the Rule Step box. 

Next, configure our rule to output a message instead of a simple true or false value. Click on Change in the Then statement next to Return [no mapping set] to map the Outcome Data [True].  Set the Mapping type as Constant, and in the Value field, fill in “This is an admin account”.

 
 edittrue

Then click on Change in the Then statement next to Else Return [no mapping set] to map the Outcome Data [False].  Set the Mapping type as Constant, and in the Value field, fill in “This is not an admin account”. 

FalseRule Screenshot

Save and close the rule.

Back in the portal, click the Create Flow button. Give the new flow a name and click OK.
createFlow

To begin our flow, add the rule just created into the workspace. It can be found in the Flow Designer start-up window, under the category Flows, Rules, Forms and Reports > Rules > [Current Folder]. Click Add to add it to the workspace.

FlowRule

 
Click on the Start step for the flow. In the Flow Data section of the Properties panel, click the Add New button.
 
In the Edit object popup, fill in the Name field with “EmailID” and click the Type selector.
 
In the Select Entity popup, select String and click OK. Click OK to save this input.
 
 addStartInput
 
Next, select the rule step – [Rule] CheckEmailID– and click the Show Mapping Editor link at the top of the Properties panel. In the Mapping Editor pop-up, map our flow input, EmailID, to our rule step’s input, also called EmailID.  Click OK to close the Mapping Editor.
 
 MappingEditor
 
Next, we want to create a form that will display the message.  Drag [Pick or Create Form] under the category Forms [Interaction] and name it DisplayAdminMessage.  Connect the CheckEmailID Rule to the Form.  
 
Edit the form to contain two components, an OK button and a Label Value for displaying the Rule result, Result as configured as pictured below.  The [Result] label can be found under Flow Data > Result> [create] label (value).  Save and close the form.
 
 Result
 

Next, connect the outcome paths of our flow.

flow

Next select the form step – [Form] Display Admin Message – and click the Show Mapping Editor link at the top of the Properties panel. In the Mapping Editor, map our rule step’s output, Result, to our form step’s input, AdminMessage. Click OK to close the Mapping Editor.

MappingAdmin

To test our rule, open our flow in the debugger. First, compare the email

 debug

The two email accounts are the same and the message returned by our rule reads “This is an admin account.”

 adminaccount

Next, test using a different email address. The message returned by our rule reads “This is not admin account.”

 notadmin

Additional Resources