Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

catalog variable exist or not

lvillasenor
Giga Expert

Need to check if a catalog variable exist or not via Business Rule from Requested Item table.

 

Any suggestion please

2 ACCEPTED SOLUTIONS

Community Alums
Not applicable

@lvillasenor Yes there is one of way to achieve same :

// Define the variable name you want to check

var variableName = 'your_variable_name';

// Check if the variable exists in the current Requested Item

if (current.variables[variableName]) {

    gs.info("Variable '" + variableName + "' exists in Requested Item: " + current.number);

    // You can also access the value using: current.variables[variableName].getDisplayValue()

} else {

    gs.info("Variable '" + variableName + "' does not exist in Requested Item: " + current.number);

}

Hope this will help you.

View solution in original post

Runjay Patel
Giga Sage

Hi @lvillasenor ,

 

You can do below in your BR.

if(current.variables['your variable name here'])
      do something
else
      do something else

 

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

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

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

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

@lvillasenor Yes there is one of way to achieve same :

// Define the variable name you want to check

var variableName = 'your_variable_name';

// Check if the variable exists in the current Requested Item

if (current.variables[variableName]) {

    gs.info("Variable '" + variableName + "' exists in Requested Item: " + current.number);

    // You can also access the value using: current.variables[variableName].getDisplayValue()

} else {

    gs.info("Variable '" + variableName + "' does not exist in Requested Item: " + current.number);

}

Hope this will help you.

Runjay Patel
Giga Sage

Hi @lvillasenor ,

 

You can do below in your BR.

if(current.variables['your variable name here'])
      do something
else
      do something else

 

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

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

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