Expression element

<< Click to Display Table of Contents >>

Navigation:  Low-code Process Automation > Studio Cloud - Authoring environment > Bizagi Studio > Process wizard > Business Rules > Business rules elements >

Expression element

Overview

Expression elements lets you 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.

 

BusinessRulesElements13

 

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.

Select parameter value

Allows quick access to parameter entities to select a value and get the id using the business key.

Syntax and reference validation

Upon clicking this button, Bizagi validates if each object included in the coded expression is referenced or not, and a grid listing all warnings, errors or additional information appears at the bottom of the expression editor.

For more information, refer to Validate expressions.

Format

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

Find and Replace

Allows you to search in the Expression content to Find or Replace specific words.

 

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 1.000 lines. When an expression reaches 1.000 lines we strongly suggest dividing it in several expressions to avoid problems at runtime.

Variables cannot be named OR, AND, IS IN, LIKE, NOT, NULL.

 

Bizagi uses IntelliSense that helps speed up the process of coding expressions, by reducing typos and common mistakes.

As a user types, Bizagi will provide quick data navigation and access to API functions.

With IntelliSense users can type '<' and the data model will be displayed, filtering by the context of the expression. We strongly suggest using IntelliSense to avoid typing the incorrect attribute or entity name.

As a user types the beginning of the method (i.e. Me, CHelper), Bizagi will display its available functions.

 

Currently IntelliSense does not display attributes that are inherited.

 

BusinessRulesElements40

 

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.

 

BusinessRulesElements14

 

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.

 

BusinessRulesElements15

 

Include the Quotations entered using the Count function found in the Data navigation category of the Function option.

 

BusinessRulesElements17

 

Include the XPath with the Data Model option. As the XPath funtions parameters should not include the angle brackets, select the option None in the XPath notation option.

 

BusinessRulesElements41

 

By default, XPaths are included with angle brackets. You can change this using the XPath notation option, where you can select if the XPath uses angle brackets (Traditional), double quotes (Quotes) or is not enclosed in any symbol (None).

 

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

 

BusinessRulesElements16

 

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.


Last Updated 4/24/2024 4:08:08 PM