Jump to content

Global constants: Difference between revisions

From Resco's Wiki
Line 30: Line 30:


;Rules
;Rules
* Form: On Save/On Change/On Load/Select Form
* Form: [[On Save]], [[On Change]], [[On Load]], [[Select Form]]
* View: Row Script
* View: [[Row Script]]
[[File:Using-constants-in-rules.png|600px|using global constants in rules]]
[[File:Using-constants-in-rules.png|600px|using global constants in rules]]
;JSBridge
;JSBridge

Revision as of 08:58, 19 August 2024

Warning This page describes a function that has not yet been publicly released, or has been released in beta / preview quality. Subject to change.
Warning Work in progress! We are in the process of updating the information on this page. Subject to change.

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?

Resco partners that create OEM products with Resco technology often want to keep a master app project where most development is done. For each of their customers, they clone the master project and tweak it to match the specific needs. In such scenarios, global constants allow Woodford administrators to change only a few values in a single spot. The constants are then used in various parts of the project, for example, on forms and views.

How to define global constants?

To define global constants:

  1. Edit an app project and select Settings > Configuration from the Project menu.
  2. Click Global Constants.
  3. 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.

define global constants in woodford configuration

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

using global constants in rules

JSBridge
  • Use MobileCRM.GlobalConstants.getAllAsync() to retrieve a list of constants
  • Use MobileCRM.GlobalConstants.getAsync("variablename") 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.