Visible, editable and required using expression

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business rules examples > Managing user interface >

Visible, editable and required using expression

This article presents examples on how to use an expression to set the basic properties of a control. These properties include whether controls are visible, required or editable.

 

Suppose a Transportation and Logistics company has defined a process called Shipping Process, to manage and monitor international shipments. The first task of this Process allows the customers to enter the information and estimate the cost of the shipment.

The company provides shipping services between Brazil, Ireland and United States. Transportation of goods can be by air, land, or sea. If the selected means of transport is air, an express service is offered for same-day shipping and delivery.

 

The data capture form to collect this specific information is as follows:

 

ManagingUserInterface

 

If the destination country is Brazil or USA, the Zip Code control will be editable and required. Otherwise, the Zip code does not apply and must be read-only.

The company offers same day express delivery service for air shipments only; this option must only displayed when the means of transport is air.

 

Configuring editability

Since the Zip code only applies to Brazil and the US, the Editable property of the Zip Code control will be evaluated once the country is selected. We will create an evaluating expression in the Editable property:

 

1. In the Form click the Zip Code control to enable its Properties in the panel on the left.

 

ManagingUserInterface5

 

2. Locate the Editable property in the Basic tab. Expand the drop-down list to view the available options.

 

ManagingUserInterface6

 

 

3. Select the last option: Expression. A new window will display.

To create a new expression click New.

 

ManagingUserInterface7a

 

The Boolean expression editor. will display

 

ManagingUserInterface7

 

 

4. Configure the required conditions. In this case our condition is related to the destination country attribute.

 

ManagingUserInterface1

 

 

Remember a Boolean expression returns TRUE or FALSE. In this case if it returns TRUE (i.e., the destination country is Brazil or USA), the control will be editable, otherwise not.

 

5. In order to evaluate this expression the Zip Code must refresh when a Country is selected; create and action and use the Refresh command to do so.

 

ManagingUserInterface52

 

In the Work Portal select Ireland as a destination country and then try to enter a zip code. Note that the Zip Code control is read-only.

 

ManagingUserInterface3

 

Select Brazil or USA as destination. The control is now editable.

 

ManagingUserInterface4

 

 

Configuring a mandatory control

Using the same example above, if the package is dutiable (taxes apply), the Declared value must be entered. To ensure this control is valued, we have to make it Required. This property's behavior will validate that a value has been entered. A warning message will display if the control is left blank.

 

Dutiable material is a Boolean control that marks if taxes need to be applied to a package or not. The Declared Value control needs to be Required depending on whether a value is entered in the Dutiable material control. Thus, an expression should be used to evaluate this condition:

 

ManagingUserInterface10

 

1. On the form click on Declared Value control. Its properties will be displayed on the Left panel.

 

ManagingUserInterface11

 

2. In the Basic properties tab find the Required behavior. Expand drop-down list to show the available options.

 

ManagingUserInterface12

 

 

3. Select the last option: Expression. To create a new expression click New.

 

ManagingUserInterface13a

 

The Boolean expression editor will display to evaluate the required condition.

 

ManagingUserInterface13

 

4. In this case the condition pertains to the Dutiable material Control value. Add a condition where the Dutiablematerial is equal to true.

 

ManagingUserInterface14

 

5. The condition needs to be evaluated, each time the user changes the value of the Dutiable material control. To enforce this, create and action and use the Refresh command.

 

 

ManagingUserInterface53

 

 

In the Work Portal when marking the Dutiable material control, note the Declared Value control becomes mandatory. This is evident by the red line marking on the left of the control.

 

ManagingUserInterface16

 

If the Dutiable material control is unchecked the Declared Value control remains optional. Note the red line marking is hidden.

 

ManagingUserInterface17

 

Showing or hiding a control

Following the example above, the express service offered by the company is only available for air shipments. The customer can select this services by means of the Express service control.

 

ManagingUserInterface8

 

To avoid selecting this service for transportation means other than air, the Express Service control must only show when the Transportation Means selected is Air. To configure this behavior follow the next steps:

 

 

1. In the Form, click the Express Service control to show its Properties in the Left panel.

 

ManagingUserInterface18

 

2. In the Basic properties tab you will find the Visible behavior. Expand the drop-down list to show the available options.

 

ManagingUserInterface19

 

3. Select the last option: Expression. Select New to create a New expression.

The Boolean expression editor will display to evaluate the required condition.

 

ManagingUserInterface20

 

4. The condition pertains to the Transportation Means Control value. Add a condition where the TransportationMean is equal to Air.

 

ManagingUserInterface21

 

5. The condition needs to be evaluated, each time the user changes the value of the Transportation means control. To enforce this, create and action and use the Refresh command.

 

ManagingUserInterface54

 

In the Work Portal select Air as a transportation means. Note that at this point the Express service control is displayed.

 

ManagingUserInterface23

 

Select Maritime as transportation means. The Express service control remains hidden from view.

 

ManagingUserInterface24

 

Show or hide controls using scripting expressions

Some Boolean conditions to be evaluated are more complex and cannot be done with the drag and drop feature in the Business Rules interface. This calls for the use of Scripting Booleans.

 

For example, suppose the transportation company has decided to offer its express service for certain air shipments dependent on the origin-destination of the package. The following table shows the shipment routes to which the express service applies:

 

Origin

Destination

Express Service Applies?

Brazil

Ireland

No

Brazil

USA

Yes

USA

Ireland

Yes

USA

Brazil

Yes

Ireland

USA

No

Ireland

Brazil

No

 

To disallow either selecting a route for shipments other than air or selecting an incompatible shipment route, the Express Service control must only be shown when the required conditions are met.

 

This behavior cannot be configured using a Boolean expression since the condition refers to different shipment route combinations . Therefore, you need to implement it using a Boolean scripting expression.

 

1. In the Form, click the Express Service control to display its Properties in the panel on the left.

 

ManagingUserInterface18

 

2.  Expand the drop-down list of the Visible behavior located in the Basic properties tab.

 

ManagingUserInterface19

 

3. Select Expression to display the expression manager.

 

4. The Expression selection window will open to select the rule (if it was already created) or to create a new rule.

 

ManagingUserInterface36

 

 

5. Expand the New options and select Scripting.

 

ManagingUserInterface35

 

 

 

6. Right click on the vertical line of the rule and add an expression.

 

ManagingUserInterface37

 

 

7. This expression calls for certain Constant definitions to be previously defined in the vocabulary, by which to reference specified entities values.

These definitions will contain the internal identifier, which is an attribute of the entity, of the specific country or transportation means.

 

 

ManagingUserInterface49

 

 

8. Type the following code and save the expression:

 

ManagingUserInterface48

 

 

//Set false if no condition is fulfilled.

var result = false;

 

//Obtain code of air transportation from vocabulary

var AirCode=CHelper.resolveVocabulary(Me,"Air");

 

//Obtain code of Brazil from vocabulary

var BrazilCode=CHelper.resolveVocabulary(Me,"Brazil");

 

//Obtain code of USA from vocabulary

var USACode=CHelper.resolveVocabulary(Me,"USA");

 

//Obtain code of Ireland from vocabulary

var IrelandCode=CHelper.resolveVocabulary(Me,"Ireland");

 

 

//Evaluate if the transportation means is air.

if (<Shipping.TransportationMean.Code>==AirCode)

{

 

 //Evaluate if shipment route is Brazil-USA.

 if (<Shipping.CountryFrom.Code>==BrazilCode && <Shipping.CountryTo.Code>==USACode)

 {

 //Set true

 result = true;

 }

 //Evaluate if shipment route is USA-Ireland.

 if (<Shipping.CountryFrom.Code>==USACode && <Shipping.CountryTo.Code>==IrelandCode)

 {

 //Set true

 result = true;

 }

 //Evaluate if shipment route is USA-Brazil.

 if (<Shipping.CountryFrom.Code>==USACode && <Shipping.CountryTo.Code>==BrazilCode)

 {

 //Set true

 result = true;

 }

 

}

 

//Return the result

result;

 

9. It is necessary to evaluate this property each time the value of the transportation means, country of origin and country of destination changes.

Create and action and use the refresh command to do so.

 

ManagingUserInterface55

 

Test the property in the Work Portal.

Select an origin-destination route that offers an express service and then select Air as the transportation means.

Note the Express Service control is shown in the Service Information group for selection.

 

 

ManagingUserInterface40

 

Now select an origin-destination route that does not offer an express service and again select Air as the transportation means. This time the Express Service control remains hidden.

 

 

 

ManagingUserInterface41

 

 

 

note_pin

When you define behaviors over the columns of a table, they will apply the entire column.

If you wish to know how to configure visibility and editability over the cells of a table, please refer to Configuring cells visibility and editability