Syntax to pass current.variables."Pass_Dynamic_Variable_Name"

Vidya Lakshmi
Kilo Sage
Kilo Sage

Hi All,

 

Can someone please let me know the right syntax to pass the internal name of the variable using current.variables."internal_variable_name"

My issue with this,

 

var VarIntName = "type_of_computer"

var VarValue = current.variables."VarIntName" // need this pass this variable value dynamically.

 

using this current.variables.type_of_computer , the value is returned as expected.

 

What should be the right syntax to use current.variables."Pass_Dynamic_Variable_Name"

2 REPLIES 2

Sagar Pagar
Tera Patron

Hi @Vidya Lakshmi,

 

Try this -

 

current.variables.variable_name;

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Sandeep Rajput
Tera Patron
Tera Patron

@Vidya Lakshmi Here is how you should provide the dynamic variable name.

 

var VarIntName = "type_of_computer";

var VarValue = current.variables[VarIntName]; // Passing the variable name dynamically
gs.info(VarValue); //prints the variable value;

//If the VarIntName holds a name of reference field then you can choose to get its display values as follows.

var VarIntName = "requester"; //assuming there is a reference type variable on form pointing to sys_user

var VarValue = current.variables[VarIntName].getDisplayValue(); // gets the display value of the reference variable
gs.info(VarValue); //prints the variable value;

 

I have tested this code on my PDI and it produces the desired result.

 

Please mark this answer helpful and correct if it manages to address your requirement.