global level variable and global level function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 08:38 AM
how to create a global level variable and global level function which can be used throughout the all business rule?
Is there any way to create it?
#ThankYou
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 08:46 AM
If you are trying to have a variable that is accessible from any BR or server side code you can try creating a system property for it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 09:17 AM
Best way to achieve this is using system property and use gs.getProperty(<system property name>); to fetch the value.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 12:57 PM
For the global variable you can use a system property in the global scope as Aman and Jonsan said. But think carefully before updating that value frequently as this will cause performance issues.
For the function you can switch to the global scope and create a Script Include:
var FooHost = Class.create();
FooHost.prototype = {
initialize: function() {
},
getFooVariable: function() {
return 77;
},
type: 'FooHost'
};
Which you can then call as follows:
var si = new global.FooHost();
var result = si.getFooVariable();
gs.info(result)