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.

How to get variable value by string name in a service catalog script?

phantom7
Giga Expert

Hello,

I am looking for a way to get a variable record through it's string name. The reason I can't use current.variables.variableName is because the variable name varies depending on the value of another record and will be a result of concatenating 2 strings. So the name will be found out dynamically at run time, so what I am looking for is something like current.variables.getVariable('variableName '). Where the variable name is a string. Is there a way of doing this?

1 ACCEPTED SOLUTION

SanjivMeher
Mega Patron
Mega Patron

You can try

 

current.variables[<var name>]


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

3 REPLIES 3

SanjivMeher
Mega Patron
Mega Patron

You can try

 

current.variables[<var name>]


Please mark this response as correct or helpful if it assisted you with your question.

Thanks a lot~

Brian Lancaster
Kilo Patron

I'm not sure you can do that but you could do something like this.

var variable = current.variables. + variableName;