Go to Project Tree > Logical Units > [LU name] > Java and then click Globals.java to open the Globals window.
Populate the settings as follows:
Click Save.
After the Global is saved, its definitions are kept in the Globals.java file under the same LU, and its initial value = Y. This variable can be used by all functions under this LU. The example below shows how to check the value of the Global variable named CUSTOMER_CHECKS_ENABLED in the CRM LU, and to determine whether to perform or to skip specific business logic (validation checks):
if (UserCode.getGlobal("CUSTOMER_CHECKS_ENABLED", "CRM").equals("Y") {
//do something
}
Notes:
The getGlobal method has 2 versions:
Invoking the Global directly by the user code returns the Global's value and does not return the overridden value if it exists. To get the Global's overriden value use either the getGlobal method or use the set command. For example:
if (ludb().fetch("SET CRM.CUSTOMER_CHECKS_ENABLED").firstValue().toString().equals("Y")) {
//do something
}
A global can be used in an SQL prepared statement in an LU function. The syntax is: '@[global_name]@'. For Integer value, the use of apostrophe is optional. Here is an example of using a global called NEW_IND:
String sql = "SELECT * From ACTIVITY WHERE CUSTOMER_ID = ? AND ACTIVITY_ID = ? AND NEW_NOTE_IND = @NEW_IND@";
ludb().fetch(sql, input1, input2).each(row->{
yield(row.cells());
});
Open the Globals window under a Logical Unit and define two new Globals and then create a new Table Population and add the Globals to it.
This example shows how a Global can be used in a Table Population. Since the SOURCE_PRODUCT_VERSION and ACTIVITY_NOTE Globals are defined in the LU’s Globals list in the Globals.java file, they are part of the LU’s scope and therefore can be used by the Table Population in the same LU.
Click to display an example of Globals under a Logical Unit in the Demo project.
This example shows how the Globals MISSING_INPUT and TOO_MANY_INPUTS can be used within a Fabric Web Service.
Three Globals are defined in the SharedGlobals.java file and therefore can be used by the Fabric Web Service.
if (contrID == "" && adrID == "") {
result = fnErrorCheck(getGlobal(MISSING_INPUT)); //Missing input
return result;
} else if (contrID != "" && adrID != "") {
result = fnErrorCheck(getGlobal(TOO_MANY_INPUTS)); //Too many inputs
return result;
}
Click to display an example of Globals under Shared Objects in the Demo project.
The following examples show how a Global can be overridden in a cluster and per session.
The RECEIVED_ERROR Global is created with an initial value of 0 and in a function its value is overridden per cluster.
if (...) {
...
fabric().execute("set_global global '*.RECEIVED_ERROR="+anotherValue+"'");
}
The RECEIVED_ERROR Global is created with an initial value of 0 and in a function its value is overridden on a session level. Check the value of the overridden variable in another function or a WS, for example to perform business logic.
In fnErrorCheck: override the global or a variable per session:
if (...) {
...
fabric().execute("set RECEIVED_ERROR="+ anotherValue);
}
The wsGetCustomerDetails Web Service calls the fnErrorCheck function and then checks the value of this variable set by the fnErrorCheck function:
Object val;
String receivedErr = "";
Map<String,Object> result = new HashMap<>();
//invoke fnErrorCheck() which sets the value of RECEIVED_ERROR
result = fnErrorCheck(input);
...
//get the value of RECEIVED_ERROR as set by fnErrorCheck() and do something...
val = db("fabric").fetch("set RECEIVED_ERROR").firstValue();
receivedErr = k2_ifNull(val.toString(),"No error");
result.put("p_error", receivedErr);
Go to Project Tree > Logical Units > [LU name] > Java and then click Globals.java to open the Globals window.
Populate the settings as follows:
Click Save.
After the Global is saved, its definitions are kept in the Globals.java file under the same LU, and its initial value = Y. This variable can be used by all functions under this LU. The example below shows how to check the value of the Global variable named CUSTOMER_CHECKS_ENABLED in the CRM LU, and to determine whether to perform or to skip specific business logic (validation checks):
if (UserCode.getGlobal("CUSTOMER_CHECKS_ENABLED", "CRM").equals("Y") {
//do something
}
Notes:
The getGlobal method has 2 versions:
Invoking the Global directly by the user code returns the Global's value and does not return the overridden value if it exists. To get the Global's overriden value use either the getGlobal method or use the set command. For example:
if (ludb().fetch("SET CRM.CUSTOMER_CHECKS_ENABLED").firstValue().toString().equals("Y")) {
//do something
}
A global can be used in an SQL prepared statement in an LU function. The syntax is: '@[global_name]@'. For Integer value, the use of apostrophe is optional. Here is an example of using a global called NEW_IND:
String sql = "SELECT * From ACTIVITY WHERE CUSTOMER_ID = ? AND ACTIVITY_ID = ? AND NEW_NOTE_IND = @NEW_IND@";
ludb().fetch(sql, input1, input2).each(row->{
yield(row.cells());
});
Open the Globals window under a Logical Unit and define two new Globals and then create a new Table Population and add the Globals to it.
This example shows how a Global can be used in a Table Population. Since the SOURCE_PRODUCT_VERSION and ACTIVITY_NOTE Globals are defined in the LU’s Globals list in the Globals.java file, they are part of the LU’s scope and therefore can be used by the Table Population in the same LU.
Click to display an example of Globals under a Logical Unit in the Demo project.
This example shows how the Globals MISSING_INPUT and TOO_MANY_INPUTS can be used within a Fabric Web Service.
Three Globals are defined in the SharedGlobals.java file and therefore can be used by the Fabric Web Service.
if (contrID == "" && adrID == "") {
result = fnErrorCheck(getGlobal(MISSING_INPUT)); //Missing input
return result;
} else if (contrID != "" && adrID != "") {
result = fnErrorCheck(getGlobal(TOO_MANY_INPUTS)); //Too many inputs
return result;
}
Click to display an example of Globals under Shared Objects in the Demo project.
The following examples show how a Global can be overridden in a cluster and per session.
The RECEIVED_ERROR Global is created with an initial value of 0 and in a function its value is overridden per cluster.
if (...) {
...
fabric().execute("set_global global '*.RECEIVED_ERROR="+anotherValue+"'");
}
The RECEIVED_ERROR Global is created with an initial value of 0 and in a function its value is overridden on a session level. Check the value of the overridden variable in another function or a WS, for example to perform business logic.
In fnErrorCheck: override the global or a variable per session:
if (...) {
...
fabric().execute("set RECEIVED_ERROR="+ anotherValue);
}
The wsGetCustomerDetails Web Service calls the fnErrorCheck function and then checks the value of this variable set by the fnErrorCheck function:
Object val;
String receivedErr = "";
Map<String,Object> result = new HashMap<>();
//invoke fnErrorCheck() which sets the value of RECEIVED_ERROR
result = fnErrorCheck(input);
...
//get the value of RECEIVED_ERROR as set by fnErrorCheck() and do something...
val = db("fabric").fetch("set RECEIVED_ERROR").firstValue();
receivedErr = k2_ifNull(val.toString(),"No error");
result.put("p_error", receivedErr);