A logic may have some parameters. Parameters are a gateway with which to communicate with the logic. These enable both application-to-logic and logic-to-logic communication. This communication enables your application to pass information of any type to the logic or to read some information from the logic.
There is no limit to the number of parameters and types of value that you can pass to and retrieve back from the logic. A parameter can be both an internal and custom type (i.e., any CLR types can be used, as well as dynamic and anonymous types). These types can be defined in different assemblies and be referenced in rules.
In FlexRule there are two types of parameters:
- Variable parameters (place holders for values)
- Type parameters
There are three directions supported within the FlexRule. Directions are for encapsulating the parameters are being defined. It can be set by the direction setting of the parameters to:
- In (Input)
- Out (Output)
- InOut (Input and Output)
Input parameters allow your application to send some input and let the logic process it.
After processing is finished, then your application can collect the result from output parameters as well. These parameters can define the decision model of logic to be collected when the process is finished.
Sometimes one parameter must act as both the Input and Output, in which case this direction type can be used.
In some scenarios, processing requires some private, local parameters to store the result into those slots temporarily and then collect them some other time. The parameters that are not part of your logic decision are called local parameters.
How to define
All logic (e.g., Flow, Procedural, Workflow, Validation, etc.) can define parameters which allows passing data and information in and out of the logic.
Please follow FlexRule Designer instruction on how to define parameters.
Passing Parameters Value
In a hierarchical logic document such as a Flow, the (parent) may contain some other logic, such as a Decision Table (child). To pass some values from parent to child logic, we need to add a Parameter with the same name in both logic documents (parent and child), and also set the context for the child to be shared.
For example, in the example below we have a Flow (as a parent) in order to find the kid's category based on their age. Our Flow contains a Decision Table (a child) to carry our rules.
Shared Context is used when the relationship between parent and child logic is simple (i.e., There is no conversion is required to pass value of Parent Parameter to Child Parameter).
In this Flow, we have an Input Parameter (which is Age) and an Output Parameter (which is Category). Now if we define both these Parameters in our Decision Table, then their context would be shared. This is because the added Parameters have the same NAME as shown below:
We have created two Parameters (Age and Category) in the Flow, and for purposing the shared context, we have created two Parameters (Age and Category) in our Decision Table.
New Context is used when the relationship between parent and child logic is not simple. This means passing parameter's value from parent to child requires conversion (e.g., sending an object (JSON) into the Flow which has some attributes that the Decision Table requires). In these cases, we need to set a mapping between the parent's parameter to the child's parameters. In the Flow, this is done by selecting the Decision Table (or other child logic) and:
- Setting the execution context to New
- Adding the map using the Parameters properties
For example, when we pass a complex structure (e.g., JSON) that has some attributes (e.g., Age) the settings below need to be applied:
- Add an input Parameter in our Flow and call it "record" (record has the Age as an attribute and we need to pass it to our Decision Table).
- Add an input Parameter for our Decision Table and call it "Age".
- Change the Decision Table's Context Mode to New.
- Add a Parameter for our Decision Table inside the Flow (select the Decision Table in the Flow/click on Properties/Parameters):
The Name is "Age" and its Value is: "record.Age"(because it is using the record's attribute which is "Age"):
- Now the Flow can be fed by a simple JSON as below: