Define and Manage Parameters

Print Friendly, PDF & Email

◷ Reading Time: 8 minutes

Introduction

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:

  1. Variable parameters (place holders for values)
  2. Type parameters

Variable Parameter

This parameter defines parameters that deal with values, either simple or complex. They can be defined in different ways:

  1. Input: Input parameters allow your application to send some input and let the logic process it
  2. Output: 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.
  3. InOut: Sometimes one parameter must act as both the Input and Output, in which case this direction type can be used.
  4. Local: 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.

    In defining variables, you have to set name which will be used to access the value in the logic. This will create an element for the Define command to define a variable parameter in logic.

    Note: if you want FlexRule Designer to list the properties of the parameters while writing expressions, the Assembly and Type must be specified.

Type Parameter

A type parameter allows the author of the logic to import or reference some:

  1. Types (class) definition
  2. Functions

to the logic, so they can be accessed during the logic execution.

Some use-cases are:

  • When you need to instantiate an object
  • When you need to access a static method of a type
  • When you need to import the methods of a type (class) as global functions in a logic

In defining types, you have to set your path which points to your type, including the namespace and name of it. This will create an element for using a command to define a type of reference in logic.

Define parameters using the Declaration Section

In the following FlexRule Designer document types you can find a Declaration section.

  1. Decision Table
  2. Flow
  3. Natural Language

In declaration section of Property Window, when the edit button is selected

Then you will have the appropriate window displayed for editing either Type or Variable parameters.

Define parameters using Toolbox

In some other forms of logic (e.g., Tree) for example Procedural trees toolbox should be used to construct the declaration section:

Procedure tree that constructed the declaration section

Toolbox to be used in creating the declaration section

Variable Types

There are some cases where you might like to add a type for a parameter. Although setting a type of parameter does not have any impact on the execution side of the logic, it enables the FlexRule Designer to provide suggestions (when possible) on the:

  1. Methods name
  2. Properties
  3. Fields

Custom Types

To set a type, just select the Assembly by choosing from the dropbox. If your assembly is not listed, you need to reference it as the project properties. Once the assembly is selected, you can then select the type by clicking on the  button.

Simply find your type and press OK.

Remember you can always enter the type address directly without using the type explorer.

This is where you can connect the Fact Concept files as well. Select the Fact Concept from the drop-down list

Then select the Type (this is the Fact name).

Default Types

If the Assembly is empty, then on the type press the  button and the list of default types will be available:

Simply select one and press OK.

Remember you can always enter the type name directly without using the helper screen.

Variable List

Logic Document Declaration

When variable parameters are defined, to view their list you don’t need to go to the managing screen. Just expand the “Variable Definition” node in the properties window.

Logic Document

When a logic document is selected in Project Explorer, then its Variable Definitions are shown in the properties window.

Direct definition

In Natural Language, in addition to the other approach, you can define Variable Parameters by using the following keywords inside your rule definition:

  1. given, input: to define Input parameters
  2. output: to define Output parameters
  3. local: to define Local parameters

Passing Parameter 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

Shared Context is used when the relationship between parent and child logic is simple (i.e., There is no conversion is required to pass the 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

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:

  1. Setting the execution context to New
  2. 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” (the 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:
 {
  "Age": 12 
 }

Type Browser

This is a window in FlexRule Designer that helps you browse and explore managed types. When you reference an assembly in your rule project, you can explore this and use the Type Browser to understand your types better.

When your project is loaded, go to,

View --> Type Browser 

or press F12 and you will see the window below:

Type Browser allows you to:

  • Explore referenced assemblies
  • Search for a type or member
  • Copy member or type name
  • Local to a type of
    • Method arguments
    • Property
    • Field

Video Description

Updated on August 14, 2019

Was this article helpful?

Related Articles