Global constants
Rules and examples |
---|
|
Woodford administrators can define project-specific constants. These can then be used in the business logic throughout the app project. Global constants require release 17.2.
Why global constants?
If you are an OEM/ISV partner managing complex projects with multiple variations, defining and using global constants across the entire project can save significant time and resources. In turn, this leads to faster deployment and more reliable outcomes. Allowing global constants to be defined once and accessed across all UI components (views, forms, select rules) significantly reduces the manual effort needed to modify multiple parts of the project when creating variations of a master project.
How to define global constants?
To define global constants:
- Edit an app project and select Settings > Configuration from the Project menu.
- Click Global Constants.
- Define constants in the same way as you would define a variable in rules editor.
- Click Variable.
- Select the type and enter a name.
- Assign a value.
The following constant types are allowed:
- Boolean
- Date Time
- Decimal
- Integer
- String
How to use global constants?
Constants can then be accessed in multiple places:
- Rules
- Available in rules configured using Woodford
- Not available in other rules, e.g., in Report Designer or Questionnaire Designer rules
- JSBridge
- Use
MobileCRM.GlobalConstants.getAllAsync()
to retrieve a list of constants - Use
MobileCRM.GlobalConstants.getAsync("constantname")
to retrieve a particular value
<script>
MobileCRM.GlobalConstants.getAsync("stringEnv").then(o => {
alert("stringEnv: " + o);
});
MobileCRM.GlobalConstants.getAsync("intEnv").then(o => {
alert("intEnv: " + o);
});
MobileCRM.GlobalConstants.getAsync("boolEnv").then(o => {
alert("boolEnv: " + o);
});
MobileCRM.GlobalConstants.getAsync("dateEnv").then(o => {
alert("dateEnv: " + o);
});
MobileCRM.GlobalConstants.getAsync("decimalEnv").then(o => {
alert("decimalEnv: " + o);
});
MobileCRM.GlobalConstants.getAllAsync().then(o => {
let str = "";
Object.keys(o).forEach(e => str += e + ": " + o[e] + "\n");
alert("all: " + str);
});
</script>
Unlike variables, constants cannot be modified, neither in the Rules editor nor in Resco Mobile CRM.