Rules editor
Rules are the most important tool for adding business logic to your Resco Mobile CRM app. Rules are scripts that are performed when a user of the mobile app opens a new view or form, taps a button or record, modifies any value, etc. You can modify many things using the scripts, most notably you change data or change the UI.
Various rules can be defined for each of the user interface components, such as form or view. They are edited in Woodford.
When you edit a UI component in Woodford, you can define actions that trigger rule execution.
| Action | Description | Form | View | Other |
|---|---|---|---|---|
| On Load | These rules are checked when you open a form. You can use these rules for example to apply custom format to certain records. | Yes | – | Questionnaire Designer |
| On Change | These rules are checked when modify any field. Example: simple form validation. They are also executed when you open a form (a new form starts empty, then the values are changed as they are loaded from the database and displayed). | Yes | Yes (*) | Questionnaire Designer |
| On Save | These rules are checked when you save a record. For example, saving a record can automatically also update a field in a parent record. | Yes | Yes (*) | Questionnaire Designer |
| Row Script | This rule is executed when a row of a list is about to be displayed. | – | Yes | – |
| On Can Execute | This rule is executed when a button is about to be displayed. Use it to control in which situations users can see and use the command, so that you can hide this command in situation, when its action is not suitable. | Yes | – | – |
| On Execute | This rule is executed when a button is pressed / tapped. It defines the actions that the command performs. | Yes | – | – |
| Button Click | Executed when an row button is clicked. | Yes | Yes | – |
| Cell Click | Executed when an editable or clickable cell is clicked. | – | Yes | – |
| On Item Added | – | – | Route plan | |
| On Item Completed | – | – | Route plan | |
| Edit Rule | Calendar rules can for example change the color of calendar entries, modify records, or make the calendar read-only. | – | – | Calendar |
(*) Applies to editable views.
Starting the rules editor
Forms and views:
- Edit an app project in Woodford.
- Select an entity from the Project menu and click Show UI.
- Edit a form or view.
- Click one of the rule buttons available in the toolbar.
Route plan:
- Edit an app project in Woodford.
- Select Route Plan from the Project menu.
- Edit a route plan.
- Click On Item Added or On Item Completed.
- If you don't see the buttons, uncheck the option View-only Mode.
Calendar:
- Edit an app project in Woodford.
- Select Calendar from the Project menu.
- Edit a calendar and go to the Rules tab.
- Select an entity and click Edit Rule.
Maps:
- Maps are based on views. View rules apply also to map views.
Using the editor
The following functions are available when editing rules.
- Save, Save & Close
- Save your changes.
- Syntax Check
- Check if the script workflow is valid. Invalid scripts cannot be saved.
- Disable Rule, Enable Rule
- Temporarily disable a rule, until you turn it back on. To permanently disable a rule, delete it.
- Edit functions
- Common functions, such as Copy or Delete, help you work with longer scripts effectively.
- Step
- Add a step. Steps do things, for example modify data or user interface.
- Say Text
- Display a message.
- Set GPS
- Variable, Shared
- Define or modify a variable. You can use the variable later in the same script. Shared variables can be used even in other scripts within the same user interface component.
- If, Else
- Use to define conditions when a particular step should be performed.
- Condition, Group And, Group Or, Ungroup
- Use Condition to add another condition to the same If. Define if the all conditions must be met (AND) or only some (OR). Use Ungroup in nested conditions.
- Export XML, Import XML
- Rules can be exported and reused in a different location in the project or in a different project.
Function types
Each variable data type will have different set of functions. See the table for details.
| Function Name | Description | Variable data types | Argument data types |
| Assign | Assigns value to variable | Text, Number, Boolean, Date | Variable data type, all types for text variable |
| Clear | Assigns null or empty value to variable | Text, Number, Boolean, Date | |
| Convert | Converts value from string | Number, Boolean, Date | String value |
| Negate | Returns negated value of argument | Boolean | Boolean |
| AddSufix | Adds argument value as suffix to variable | Text | Text, Number, Boolean, Date |
| AddPrefix | Adds argument value as prefix to variable | Text | Text, Number, Boolean, Date |
| Concat | Returns concatenated string from two arguments | Text | 2 args: Text, Number, Boolean, Date |
| Concat3 | Returns concatenated string from three arguments | Text | 3 args: Text, Number, Boolean, Date |
| Format | Returns formatted string from StringList | Text | Arg1: Text; Arg2: StringList |
| Addition | Returns addition of arguments | Number | Arg1: Number; Arg2: Number |
| Difference | Returns difference between first and second arguments | Number | Arg1: Number; Arg2: Number |
| Multiplication | Returns product of arguments | Number | Arg1: Number; Arg2: Number |
| Division | Returns division of arguments | Number | Arg1: Number; Arg2: Number |
| SetNow | Assigns current time to variable | DateTime | |
| SetToday | Assigns current day to variable | DateTime | |
| SetTomorrow | Assigns tomorrow to variable | DateTime | |
| AddMinutes | Returns DateTime argument plus X minutes | DateTime | Arg1: DateTime; Arg2: Number |
| AddHours | Returns DateTime argument plus X hours | DateTime | Arg1: DateTime; Arg2: Number |
| AddDays | Returns DateTime argument plus X days | DateTime | Arg1: DateTime; Arg2: Number |
| AddWeeks | Returns DateTime argument plus X weeks | DateTime | Arg1: DateTime; Arg2: Number |
| AddMonths | Returns DateTime argument plus X months | DateTime | Arg1: DateTime; Arg2: Number |
| AddYear | Returns DateTime argument plus X years | DateTime | Arg1: DateTime; Arg2: Number |
| AddItem | Adds argument to end of list. | StringList | Arg1: Number, Boolean, String, DateTime |
| InsertItem | Adds argument to specified index. Index starts at 0. | StringList | Arg1: Number, Boolean, String, DateTime; Arg2: Number |
| GetItem | Returns item at specified index. | StringList | Number |
| RemoveItem | Removes item at specified index | StringList | Number |
| ClearItems | Removes all items from list variable | StringList | |
| Function | Description | Variable data types | Argument data types |
Text = String, Memo
Number = Integer, Float, Decimal, Number