Table of Contents

Global Variables

The Global Variables module permits us to customize the functionality of the application in a very easy way. The basic idea is that when we are programming something and need to establish a value or a decision, we create a global variable with a default value and use the result. So now any user can set the global variable to another value and effectively modify the program logic without having to modify the code. A really powerful and easy extension.

The order Global Variables use to return a value is:

Example

Let's suppose I needed the invoice creation to leave the status of the related sales order alone. So I set my Global Variable up like this:

You could also set a different value if you do want the SalesOrder status to change, but not to “Approved”.

Fields

Documentation

The list of variables is fully documented in the module itself. On the list view, there is a button to access the table, on the detail and edit view there is a block which contains the table with all the variables, their possible values and an explanation of what each is for.

Test

On the list and detail view, you will find a Test action which will permit you to validate the result of any variable on any module for any user. This is very useful when you have a lot of records for the same variable and need to make sure that the right value will be returned in each case.

Web service

External applications can get the values of global variables in the application using the web service call: SearchGlobalVar, which is a GET request with three parameters:

  1. gvname: name of the global variable
  2. defaultvalue: default value to be returned if not found
  3. gvmodule: module to be searched on

You can see an example of this call and try it out using the coreBOS web service developers' tool.

This web service endpoint has a special use case to retrieve business maps. Since business maps are such a powerful configuration feature and the exact map to use for each user/module depends on the global variable module escalation rules, this web service method will recognize the prefix “BusinessMapping_” in the first gvname parameter. If the name has this prefix it understands that you are searching for a Business Map and will return the ID of the map along with the map itself in JSON format.

SearchGlobalVar('BusinessMapping_Accounts_FieldDependency', '', 'Accounts');
array(
  'id' => business map WSID,
  'map' => JSON string of the map,
);

JavaScript

In the browser we have a JavaScript promise that sets the value obtained from the application like this:

var calendar_call_default_duration = 5; // define the variable and set it's default value
GlobalVariable_getVariable('Calendar_call_default_duration', 5, 'Calendar', gVTUserID).then(function(response) {
	var obj = JSON.parse(response);
	calendar_call_default_duration = obj.Calendar_call_default_duration;  // set value from application
}, function(error) {
	calendar_call_default_duration = 5; // set default value on error
});
// You MUST give this some time to execute, so do not use the value at this line, or
// execute your code inside the promise

Create a new variable

Creating a new variable is a three step process

  1. call the global variable method with the new variable in your code
  2. add the new variable to the DefineGlobalVariables.php continuous changeset so it gets added to the picklist of valid variables
  3. add the definition of the new variable in the language file

This commit is a good example of this process.

More Information

You can find some more information here