Expression element

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business rules elements >

Expression element

Overview

Expression elements allow you to enter instructions as code to carry out any type of task. Expressions can perform calculations and validations using XPath functions.

 

The Expressions interface has several options that allow easy interaction and accelerates the Process of writing a rule.

 

Business Rules Elements13

 

OPTION

USE

Data Model

Allows you to build XPaths to use in the expression. Additionally you can edit the data model and include values to parameter entities.

Function

Includes a list of functions to combine the XPaths built with the data model. Functions are organized in categories and include a description and an example.

You can search for a function if you already know its syntax, or a part of it.

For more information refer to XPath functions

Library Rules

Gives access to the existing Library rules created for the project. When a rule is selected Bizagi resolves and displays the return value and the parameters and their corresponding types.

For more information refer to Library rules

Vocabulary

Displays a list of the vocabulary that can be included in the expression. If the business rule is created as a global expression, only global vocabulary will be available. If created as application expression, the global and the application vocabulary will be available.

Variables

Allows quick access to manage variables to create, edit and delete them. Once a variable is created, select it from the drop-down list to use it in the expression.

Format

Allows several formatting options:  save, cut, copy, paste, undo, redo, increase or decrease indent.

 

 

note_pin

The XPaths, functions, vocabularies and variables that are selected will be included at the cursor insertion point.

There is a size limit for Expressions of 100.000 characters which in average is 1000 lines. When an expression reaches 1000 lines we strongly suggest dividing it in several expressions to avoid problems at runtime.

 

Bizagi uses IntelliSense to display functions and XPaths and allows you creating expressions in a easier and faster way.

 

Business Rules Elements40

 

 

We used the expression element in a previous example, if you want to review it please refer to: Expression element example

 

Example

In a Purchase Request process, when the purchase has been approved it is necessary to perform quotations and select the best supplier.

However, it is required to include a specific number of quotations for the selection process. The user will not be able to continue unless the required number of quotations have been reached.

 

We will use an expression element to evaluate if the required number of quotations have been included. If not, a validation message will be sent to the end user to correct the situation.

 

Add an Expression element to the business rule and name it.

 

Business Rules Elements14

 

 

Create an If function to evaluate the number of quotations required versus the number of quotations included.

As the first parameter include the number of quotations required using the Data Model option.

 

Business Rules Elements15

 

Include the Quotations entered using the Count function found in the Data navigation category of the Function option, and include the XPath with the Data Model option.

 

 

Business Rules Elements17

 

 

note_pin

When an XPath is included using the Data Model option, it includes the angle brackets. REMEMBER TO DELETE THE ANGLE BRACKETS WHEN USING XPATH FUNCTIONS

 

Include the Validation message, using the Throw Validation error function found in the Data Validation category.

 

 

Business Rules Elements16

 

The final code will be:

 

if (<PurchaseRequest.NumberOfQuotationsRequir> > <count(PurchaseRequest.Quotation)>)

CHelper.ThrowValidationError("You need at least "+ <PurchaseRequest.NumberOfQuotationsRequir> +"quotations");

 

note_pin

Always use double equal signs ( == ) when performing value comparisons. The single equal sign corresponds to an assignment operator and will always be true.