Jump to content

Global constants: Difference between revisions

From Resco's Wiki
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Beta}} {{WIP}}
{{Rules TOC}}
Woodford administrators can define project-specific constants. These can then be used in the business logic throughout the app project. Global constants require [[Releases/Fall 2024|release 17.2]].
Woodford administrators can define project-specific constants. These can then be used in the business logic throughout the app project. Global constants require [[Releases/Fall 2024|release 17.2]].


== Why global constants? ==
== Why global constants? ==


For OEM/ISV partners who manage complex projects with multiple variations, the ability to define and use global variables across the entire project can save significant time and resources, leading to faster deployment and more reliable outcomes. Allowing global variables 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.
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? ==
== How to define global constants? ==


To define global constants:
To define global constants:
# Edit an app project and select '''Settings > Configuration''' from the Project menu.
# Edit an app project and select '''Settings > Configuration''' from the [[App_projects#Project_menu|Project menu]].
# Click '''Global Constants'''.
# Click '''Global Constants'''.
# Define constants in the same way as you would define a variable in [[Rules_editor#Using_variables|rules editor]].
# Define constants in the same way as you would define a variable in [[Rules_editor#Using_variables|rules editor]].
Line 30: Line 30:


;Rules
;Rules
* Form: [[On Save]], [[On Change]], [[On Load]], [[Select Form]]
* Available in rules configured using Woodford
* View: [[Row Script]]
* Not available in other rules, e.g., in Report Designer or Questionnaire Designer rules
 
[[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 - [https://github.com/Resconet/JSBridge/wiki/MobileCRM.GlobalConstants MobileCRM.GlobalConstants]
 
* Use <code>MobileCRM.GlobalConstants.getAllAsync()</code> to retrieve a list of constants
* Use <code>MobileCRM.GlobalConstants.getAllAsync()</code> to retrieve a list of constants
* Use <code>MobileCRM.GlobalConstants.getAsync("variablename")</code> to retrieve a particular value
* Use <code>MobileCRM.GlobalConstants.getAsync("constantname")</code> to retrieve a particular value


<syntaxhighlight lang="JavaScript">
<syntaxhighlight lang="JavaScript">

Latest revision as of 11:46, 20 February 2025

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:

  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
  • Available in rules configured using Woodford
  • Not available in other rules, e.g., in Report Designer or Questionnaire Designer rules

using global constants in rules

JSBridge - MobileCRM.GlobalConstants
  • 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.