How to configure a flow that prompts users to provide values needed for a calculation (backward chaining through goal seek)
“Backward chaining” and “forward chaining” are phrases that describe the ways that declare expression rules perform their computations.
Consider a spreadsheet with a column of figures and a total value. If the total is updated each time you change any of the inputs in the column, that’s similar to forward chaining. In its simplest state, backward chaining would be if the total doesn’t change until you click on the total or on a button that causes the calculation. But backward chaining is a little more complicated than that. What if the values of one or more of the rows included in the total are also calculated values? Backward chaining would cause each of those values to be calculated, as well. Furthermore, if some calculated values were dependent on others, backward chaining would determine the correct order and perform the calculations in that order.
When you configure a declare expression rule, specifying that it should calculate its value whenever inputs change implements forward chaining. Backward chaining occurs when you specify that it should calculate its value when the target property is used. For an example, consider three declare expression rules that calculate values for properties X, B, and D as follows:
Assume that X and B should be calculated whenever inputs change and the value of C changes. In this case, the chain of calculations begins with calculating B and ends with calculating X. That is a forward chain.
Now assume that the value of X is to be calculated only when it is used. When the value of X is requested, Process Commander first determines the dependency network of calculations by traversing backward through the chain so it can determine the correct starting point for the calculation. Then it runs the declare expression rule for D, the declare expression for B, and finally the one for X. This is backward chaining.
You can trigger a backward chain of calculations no matter how the declare expression rules are configured with the goal seek feature. That is, even if none of the inputs have changed for an expression that is configured to run only when inputs change, goal seek triggers the calculation. Goal seek begins by searching for the values of the inputs needed for the calculation. If any inputs are missing, goal seek reports them. You then configure your application to respond by either acquiring the missing values programmatically or by prompting a user to enter a value.
Goal seeking can be implemented in several ways — by writing an activity that uses the Property-Seek-Value activity method, or by adding a standard flow action named VerifyProperty to your flow, for example. This rest of this article describes how to use the VerifyProperty flow action to prompt a user to supply a missing value required by a declare expression rule.
To configure your application to prompt a user to supply a value needed for a declare expression to calculate its value, use the standard flow action named VerifyProperty and specify the target property, which identifies the declare expression rule to run.
Create the declare expression rule(s)
First, determine the property you are interested in and create the declare expression rule (Decision > Declare Expressions > New). In the following example, the target property is named GrandTotal:
Note that the value of one of the inputs in the example expression, pyChargeAmount, is also calculated by a declare expression rule:
Because both GrandTotal and pyChargeAmount are configured to calculate whenever inputs change, a change to either of the inputs for pyChargeAmount (pyChargeRate or pyEffortActual) would cause a forward chain of calculations for both pyChargeAmount and GrandTotal.
Save the VerifyProperty flow action to an application RuleSet and edit it
The Work-.VerifyProperty flow action runs an activity, also named VerifyProperty. To use the flow action, save it into one of your application RuleSets (save as) so you can edit it and specify the property you want calculated in the input parameter for the activity.
1. Locate and open the Work-.VerifyProperty flow action and save it into the appropriate application RuleSet.
2. Change the short description to something meaningful for your application because that is the value that appears in the list of possible actions in the assignment form.
3. Select the Action tab. In the Before this Action section, change the value in the GoalProperty parameter to your property.
4. In the After this Action section, change the value of the GoalProperty parameter to your property.
To continue with the example, the figure shows the short description set to “Compute Grand Total” and the GoalProperty set to GrandTotal.
Use the VerifyProperty flow action in your flow
Open or create the flow rule and locate the appropriate assignment shape.
In the Assignment Properties panel, in the Local Actions section, specify the VerifyProperty as a local action. For example:
Note that in the example, the harness specified is the Perform_ButtonsTabbed harness, which means the flow actions appear as buttons or links.
Test the flow
When you are finished adding the flow action to the flow, create a work object to preview the work object forms. In the following figure, the Take Action section of the Display Home assignment used for this example lists the VerifyProperty local action as a link named Compute Grand Total (its short description):
When you click the Compute Grand Total link from this example form, goal seek runs the declare expressions rule for the Grand Total property to start the chain. If, for example, the value for Sales Tax is missing, the user is prompted to supply it:
Because the value for GrandTotal also depends on the value of pyChargeAmount, the declare expression rule for pyChargeAmount is part of the dependency network in the chain. If the value for pyChargeAmount were missing, backward chaining would trigger the declare expression for pyChargeAmount before running the declare expression for Grand Total.