Default value using expressions

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Business Rules > Business Rules examples > Cases and activities > Managing user interface >

Default value using expressions

When the default value option is used for controls that are relating a table, such as combos or lists, they receive the identifier of the record that wants to be displayed. That is, the expression used must return an integer. Make sure the identifier is actually found in the related table.


The following example illustrate how to set a default value for a control.



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 shipments.

The company provides shipping services between Brazil, Ireland and United States. Transportation of goods can be by air, land, or sea. If the transport mean selected is air, the express service is offered in order to deliver packages the same day they are sent.


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




The company requires initially the country of origin to be that of the person entering the shipping information. Later, the customer may choose the shipment to originate from a different country. An expression is needed to identify the user's country of residence and assign this value to the country of origin. Bear in mind, for this expression to work correctly, that Country must be allocated as a user property for all users.


1. Select the Origin Country control to display its Properties in the panel on the left.




2. Locate the Default value behavior in the Advanced properties tab. Click the expression icon to display the Expression editor.




Select New to create a new expression.




3. Add an expression module.  




4. Enter the following sentence and save the expression:




//Returns the ID of the country specified in the user properties of the current user.




The user property name (in this example idCountry) corresponds to name of such attribute within the WFUSER Entity. In order to find this name, go to the Entities module in the Expert view.




5. Test the default value in the Work Portal. Create a new case and see how the Country (From) is automatically filled.

Remember to add Country as a user property of all users.


Log in as a user from Brazil and create a new case. Notice the country of origin is the value held in the user property.





Keep in mind that the type of value returned in the expression must coincide with the type of value that the control manages (e.g dates with dates, integer with integer). If they are different, errors may occur in the execution of the form.