Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

global level variable and global level function

KausikSharma
Tera Contributor

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 

3 REPLIES 3

jonsan09
Tera Sage

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.

Aman Kumar S
Kilo Patron

Best way to achieve this is using system property and use gs.getProperty(<system property name>); to fetch the value.

 

Best Regards
Aman Kumar

thomaskennedy
Kilo Sage

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)