<< Click to Display Table of Contents >> 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:
•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.
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.
2. Locate the Editable property in the Basic tab. Expand the drop-down list to view the available options.
3. Select the last option: Expression. A new window will display.
To create a new expression click New.
The Boolean expression editor. will display
4. Configure the required conditions. In this case our condition is related to the destination country attribute.
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.
6. 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.
7. Select Brazil or USA as destination. The control is now editable.
Default option for the command change editability for using Actions and Validations
In the Form's Actions the behavior of the editability of controls differ from how they work with Expressions.
•When being editable or read only, set through Actions, the instruction is inherited for the entire set of controls where it they are used. If attributes are contained in a group (such as a reusable form, group, panel), the editable or read-only instruction apply for all of them, regardless of their initial property.
•In Expressions, when it returns true, the controls are editable or read-only according to their initial state.
There is a Default option in Actions that can be used when controls are contained in a group (such a reusable form, group, panel). If the command change editability for is set to default, the original configuration of each control is kept.
Refer to Make a control editable or read-only for more information.
Configuring a mandatory control
Using the same example above, if the package is dutiable (taxes apply), the Declared value must be entered. To make sure 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:
1. On the form click Declared Value control. Its properties will be displayed on the Left panel.
2. In the Basic properties tab find the Required behavior. Expand drop-down list to show the available options.
3. Select the last option: Expression. To create a new expression click New.
The Boolean expression editor will display to evaluate the required condition.
4. In this case the condition pertains to the Dutiable material Control value. Add a condition where the Dutiablematerial is equal to true.
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.
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.
If the Dutiable material control is unchecked the Declared Value control remains optional. Note the red line marking is hidden.
We strongly suggest that if you choose to control visibility using Expressions, then have all visibility definitions with expressions. Beware that combining visibility Actions & Validations with visibility Expressions will most likely fail at runtime. If you want to configure a control's visibility, we recommend using Actions & Validations. |
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.
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.
2. In the Basic properties tab you will find the Visible behavior. Expand the drop-down list to show the available options.
3. Select the last option: Expression. Select New to create a New expression.
The Boolean expression editor will display to evaluate the required condition.
4. The condition pertains to the Transportation Means Control value. Add a condition where the TransportationMean is equal to Air.
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.
6. Once again click the Express Service control to show its Properties in the Left panel. In the Advance properties tab turn on the Submit on change option.
Using the Submit on change property may produce delays or timeouts in the form. If you want to configure a control's visibility, we recommend using Actions & Validations. |
In the Work Portal select Air as a transportation means. Note that at this point the Express service control is displayed.
Select Maritime as transportation means. The Express service control remains hidden from view.
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.
2. Expand the drop-down list of the Visible behavior located in the Basic properties tab.
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.
5. Expand the New options and select Scripting.
6. Right click the vertical line of the rule and add an expression.
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.
8. Type the following code and save the expression:
//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.
10. Once again click the Express Service control to show its Properties in the Left panel. In the Advance properties tab turn on the Submit on change option.
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.
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.
When you define behaviors over the columns of a table, they will apply the entire column, regardless of its visibility, given that the columns are included in the metadata of the project. 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 |
Last Updated 7/21/2023 3:53:23 PM