Using "IF" script to check for a Variable Set Value

ZacharyW
Tera Expert

Hello,

I have a variable set called "User Data" that populates on my service portal requests. One of these variables is a "location" variable. I am building a workflow that needs to check for this location, then generate tasks accordingly. I'm using a basic "IF" statement in the workflow to check, but I'm unable to figure out what's going wrong.

How do I check for a variable set variable in a workflow?

Using current.variable_pool.location doesn't work, as it doesn't seem that the variable set location variable exists within the variable pool.

Perhaps the variable I need is stored on the Request table? In which case how do I call that?

Here is the "IF" statement that I'm using:

---------------------------------------------------------------------------------

answer = ifScript();

function ifScript() {

if (current.request.requested_for.location == "30bc3793db191fc014a0777a8c9619d7")

       return 'yes';

else

       return 'no'; 

}

---------------------------------------------------------------------------------

 

Thank you for all the help!

1 ACCEPTED SOLUTION

Manish Vinayak1
Tera Guru

Hi,

You should try accessing the variable by the following call:

current.variables.variable_name;

But that won't work for Multi-Row Variable Sets. To access multi-row variable set's variables, you need to specify the internal name of the variable set:

current.variables.variable_set_internal_name.variable_name;

Note: Accessing the variables using the variable set internal name, i.e.,

 current.variables.variable_set_internal_name.variable_name

works for both Multi-Row Variable set and Single Row Variable Set.

 

Hope this helps!

Thanks,

Manish

View solution in original post

4 REPLIES 4

The Machine
Kilo Sage
current.variables.variable_name works. Give that a try

Raf1
Tera Guru

Hi Zach,

 

Try this:

answer = ifScript();

function ifScript() {

if (current.variables.location == "30bc3793db191fc014a0777a8c9619d7")

       return 'yes';

else

       return 'no'; 

}

Regards,

Raf

Manish Vinayak1
Tera Guru

Hi,

You should try accessing the variable by the following call:

current.variables.variable_name;

But that won't work for Multi-Row Variable Sets. To access multi-row variable set's variables, you need to specify the internal name of the variable set:

current.variables.variable_set_internal_name.variable_name;

Note: Accessing the variables using the variable set internal name, i.e.,

 current.variables.variable_set_internal_name.variable_name

works for both Multi-Row Variable set and Single Row Variable Set.

 

Hope this helps!

Thanks,

Manish

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

if you want to get value from request table then do this

 

current.request.requested_for.location

if you want to get it from some variable then irrespective whether it is inside variable set or not use this

current.variables.<variableName>

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader