How to configure rules in the web form
Prerequisites
Introduction
Rules are mechanisms that cause a form to display fields, hide them, or make them mandatory in different situations.
They are used to define the actions that must be executed in accordance with the information inserted in the form. Actions allow for comparing inputted information, editing field properties, displaying a message on the screen, executing another rule, and executing a dataset to fill in form variables with the result of this execution.
Due to the specific demands of each organization, it is up to the user to define and develop their own formulas, adapting them to their needs. Depending on the complexity of the rules needed, it may be necessary to be familiar with programming logic concepts.
See how the formula editor workspace is divided and learn how to configure some types of rules in the forms:
Formula editor workspace
The formula editor can be accessed in two ways:
General form rules
1. Access the File > Form (FO005) menu.
2. Select the form in which you want to configure rules.
3. Click on the arrow next to the button and select Form designer.
4. From the toolbar, click on the arrow of the Rules field and select Load or Save/Finish.
Rules related to a form field
1. Access the File > Form (FO005) menu.
2. Select the form in which you want to configure rules.
3. Click on the arrow next to the button and select Form designer.
4. In the designing area, select the desired field to display its properties.
5. In the rules section of the properties field, select for which form event a rule will be configured: Input, Output, Change, or Click.
Upon accessing the formula editor workspace, you will see the screen divided as follows:
A - This area displays the formula editor toolbar. The buttons shown may vary, as they may have specific functions of the component in which the formula editor was accessed.
B - This area displays the editing space. The formulas or functions can be typed or selected from the toolbar.
C - This is the presentation area of the formulas. Once a function or formula is inserted in the editing area, the presentation area updates as well; however, in this area, information is displayed with its corresponding format.
Configuring rules
1. Access the File > Form (FO005) menu.
2. Select the form in which you want to configure rules.
3. Click on the arrow next to the button and select Form designer.
4. Configure the desired rule:
Rule for enabling/disabling form fields
It is common for a form to have rules that disable fields when an option is selected.
A simple example is a set of radio buttons for identifying marital status (Single/Married). In this example, when the user selects the "Married" option, the "Spouse name" field of the "Spouse" area must be enabled.
For a better understanding of the rule before configuring it, a good practice is to write the formula (rule) in a simple and concise manner:
- When the user clicks on the "Married" field, the "Spouse name" field of the "Spouse" area must be enabled. Any selections in the other radio buttons of the "Marital status" area must be cleared as well.
The "when" in the description above is determined by the click event in the "Married" radio button. The action for enabling the "Spouse name" field and unchecking the other radio buttons is determined by the "ACTION" function.
Click on the function, in the presentation area; on the parameter screen, select all the form fields that will be changed with the click on the "Married" radio button. Use the columns of the parameter screen to enable the "Spouse name" field and clear the fields of the other radio buttons.
See further details in the image below:
How to use variables
Variables are used to store values at several spots in the formula. A common example is to search for the value of a field and compare it multiple times in the formula in order to enable/disable fields depending on the value.
To create a variable, simply type a letter or word followed by the = (equal) character and the value of the variable. The value may be a number (result of a calculation), a text (in this case, wrapped in single quotation marks), or the value of a form field.
How to use conditions (IF/ELSE) to enable fields, in accordance with the value of another field
Conditions are meant for cases in which the user wishes to verify the value of a field and, depending on said value, enable some fields or disable/hide others.
To enable/disable fields, the ACTION function must always be used. The following image displays an example that fetches the value of a field and stores it in a variable for it to be used in the conditions:
A - Fetches the field value and stores it in the v (value) variable.
B - If the v value is equal to 'John', that is, if the issuer's name is equal to 'John', the action for enabling the 'starttime' field will be applied.
C - If the v value is equal to 'Anne', that is, if the issuer's name is equal to 'Anne', the action for making the completion of the 'starttime' field mandatory will be applied
For each IF/ELSE command, the END command is required. The ACTION function is assigned to an x variable, since, during the formula building process, the function needs to have a variable that returns the value applied within the function – in this case, a variable that returns the action applied to the fields.
The user can also enter RETURN ACTION(...). The FIELDVALUE function uses 2 parameters: entity ID # and entity attribute ID #. To facilitate, when opening the parameter configuration screen, the system brings the entity of the current form right away.
How to fetch a selected value from a list (combobox/zoom)
Fetching a value from a list (combobox/zoom) is similar to fetching a value from another field (input, etc.). Simply use the LISTVALUE function instead of FIELDVALUE.
The LISTVALUE function allows for fetching a selected value that is not shown on the screen.
See an example in the image below:
The LISTVALUE function has 3 parameters: entity ID #, relationship ID # (the same used in the combobox/zoom properties in the form), and attribute ID #.
When opening the screen for configuring the parameters of the function, the system automatically brings the source entity of the current form. Simply select the relationship and the attribute you wish to fetch.
How to insert value in a field via formula
To insert a value in a field via formula, use the same function that enables/disables fields. The last parameter can provide a variable containing the value to be inserted.
The image below shows an example:
How to perform calculations with values inserted in the form
For calculations, math functions must be used: Sum, Product, etc.
See further details in the following images:
A - Sum operations.
B - Product operations.
C - Subtraction and division operations.
D - In cases of division of a decimal number, multiply the decimal value by 1 and then proceed with the division.
The SUM and PRODUCT functions have parameters, which are the values of the operation, separated by semicolon (;).
In cases of division of a decimal number, multiply the value by 1 before proceeding with the division, as the system needs to convert the separator ("," or ".") of the decimal places to a single format.
Any field information included in the rule through the FIELDVALUE function returns to the rule as text. The data needs to be transformed into a number so that the calculations are executed correctly. To this end, the function for multiplying by 1 is used.
How to set field values using calculation results
To set a value in a field using the result of a calculation, simply perform the calculation and use the ACTION function to insert the value in the field.
The following image displays an example that multiplies two fields and sets the value with the result in the total field:
How to set field values using logged users' names
To set a value in a field using the logged user's name, the ACTION function will be used. The name of the logged user can be fetched through the LOGGEDUSER function.
See further details in the image below:
How to set field values using process starters
To set a value in a field using the starter of a process, the ACTION function will be used. The name of the process starter can be fetched through the STARTER function.
See further details in the image below:
This function can be tested only through the execution of a process in SoftExpert Workflow.
How to enable form fields according to process activities
To enable fields according to an activity, first search for the ID # or name of the activity to use it in the conditions. To this end, the ACTIVITY function is used, which fetches the current activity in which the form is viewed.
After that, create the conditions (IF/ELSE) and use the ACTION function to enable/disable fields.
The image below shows an example:
How to use the ID of a user to make the system fetch their name, age, etc.
This example is used for cases in which the ID or code of a user is typed, and the system fetches, from the other entities (tables), their name, age, marital status, etc.
To carry out this task, execute the following procedure:
- In the output event of the ID field, create a formula.
- In the formula, first search for the value of the ID field (usrregistry) and store it in a variable (usr_registry). The FIELDVALUE function is used.
- Create a filter with the ID value in the entity that has data such as name, age, etc. ('E002 - Employee' entity). The TABLEFILTER function is used.
- Fetch name and age in the entity (E002 - Employee) using the filter created above and store them in variables ('var_nm' and 'var_age'). The FIELDVALUEFILTER function is used.
- Enter name and age in the form fields using the ACTION function.
See the application of the steps in the image:
A - Fetches the ID (usrregistry) inserted by the user in the form.
B - Creates a filter in the 'E002 - EMPLOYEE' entity through the 'registryid' attribute.
C - Fetches name and age in the 'E002' entity through the filter.
D - Fills in the Name and Age fields in the form with the value of the variables.
How to calculate grid column total
The column does not need to be shown in the grid, as it is considered a column of the table.
To calculate the total value of the column, use the TOTALGRID function. This function is meant for specifying the relationship, the grid table (same data inserted in the properties of the grid), the field to be calculated, and the operation (Sum, Average, Maximum, Minimum, Counter). After the calculation, the result can be entered in a form field via the ACTION function.
A - Calculates the total of the grid column (TOTALVL).
B - Fills in a decimal field with the result.
How to disable all FieldSet fields
To apply actions to all items positioned in a FieldSet, the GROUPACTION function can be used. Enter the ID # of the FieldSet and specify the actions to be executed.
This option is used for cases in which several sections of the form are meant to be disabled or hidden. To apply more than one FieldSet, simply repeat the line by changing the ID # for each FieldSet.
How to hide/display a title or image
To hide or display fields of the title or image type, use the ACTIONITEMLAYOUT function. This function is similar to the GROUPACTION one.
Enter the ID # of the title item or image item and specify the actions to be performed.
How to insert value in the title
To insert value in the title, use the ACTIONITEMLAYOUT function. Enter the variable with the value to be inserted only in the last parameter.
The image below shows an example:
Example for calculating age from birth date
For age calculation, use some functions of the date toolbar button.
The image below shows an example:
A - Fetches the birth date entered in the form.
B - Fetches today's date through the TODAY() function.
C - Separates dates as year, month, and day.
D - Calculates age by subtracting the current year from the birth year.
E - Checks if the user has had their birthday in the current year. If they have not, their age decreases by one year.
F - Fills in the value of the age field with the calculated age.
Calculation with Time field
It is possible to calculate the number of hours between two fields of the Time type.
The following image shows an example referring to a Time field and the current time:
How to use the ACTION, GROUPACTION, and ACTIONITEMLAYOUT functions in the same formula
It is possible to use the ACTION, GROUPACTION, and ACTIONITEMLAYOUT functions combined. There are cases in which the intention is to have only one item enabled in a FieldSet, and the other ones disabled.
To handle this case, all FieldSet items can be disabled with the GROUPACTION function; then, the desired field can be enabled with the ACTION function. The sequence of the actions is followed.
The image below shows an example:
A - Disables all items within the FieldSet.
B - Enables the Total field only.
The system does not allow for saving formulas containing one of the EXECUTESQL, OPENSQLZOOM, and UPDATEGRIDZOOMSQL obsolete functions, whether when creating or editing the formula.
Practical example
An example of a rule can be verifying the value of a field and performing actions on other fields. The actions are: enable, disable, mark as required, mark as not required, display, hide, clear, load, and apply value to a field.
In the example used, fields were added for the approval of the travel request. Using the rules, it is possible to disable the "No" CheckBox when the "Yes" CheckBox is selected, and vice versa.
Conclusion
It is possible to create numerous formulas to manipulate form fields as needed. Check out the Formula editor for further details on how to build formulas.