Global Variables

Dazler
Mega Sage

Hi,

 

I was thinking of making many of my variables global, so that they can show up on the catalog task without having to use the slush buck in Flow Designer.  Before I do that, I want to know if there is any downside to doing that?

 

I am asking this because we use Flow Designer more than we use Workflow Editor.  However, in workflow editor is it much easier to handle variables when you have 1 workflow setup for multiple catalog items.  In the slush bucket of the create catalog task activity you are choosing by variables, however, with Flow Designer you are choosing the variable set or the actual catalog item.  It makes it much more difficult to to create 1 flow for multiple catalog items unless you set the variables as global.

 

Can setting the variables global cause any platform issue?

9 REPLIES 9

Tony Chatfield1
Kilo Patron

Hi, I believe that global variables would consume resource and increase the risk of a variable value being incorrect as accessed outside of the context in which it was created\populated.

Hello, I couldn't find much documentation discussing global variables. Could you explain more on that second part? I'm curious what could all happen when you mark a variable as global.

Hi, if a variable is 'global' then it is accessible from all scopes\all functions.
Meaning that it can be read or written too from anywhere\by anyone, so if userA runs functionA and sets a value for a global variable, user2 (or another function from user1) might read user1's value or change the value so that is no longer correct for user1/functionA.
Global Variables in JavaScript Explained (freecodecamp.org)

Ah, alright. So they are treated as actual global variables in scripting, etc. I wasn't sure how ServiceNow was treating that field / functionality.

 

So once we'd mark that as global, it is no longer exclusive to that catalog item. It may get picked up by other scripts we have running that modify that variable. If that is the case, that is a pretty dangerous thing to be using and ServiceNow really needs to get their Docs site updated.