Scripting Against a Dynamic Variable

bassasam
Giga Contributor

Hi,

I am trying to do this in a workflow. I am trying to check a value of particular 'catalog variable' from the submitted RITM, and the catalog variable varies for every catalog. I will pick this variable name from a table.

I am trying out the below script in the background, where action is the name of the catalog variable.

it is getting into the loop even if the   value is NOT test.

var action = 'setas_actions';

var query1='ritm.variable_pool.'+action+'=test';

gs.print(query1);

var ritm = new GlideRecord('sc_req_item');

ritm.addQuery('number','RITM0022368');

ritm.addEncodedQuery(query1);

ritm.query();

if(ritm.next()){

//gs.print('ritm.variables.'+action);

gs.print('Hi');

}

Some help pls.

Thanks,

Sam

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If the variable is for the current ritm, you could do something like:



var variableName = 'varName'; //you would pull this dynamically from your table


var variableValue = current.variables[variableName];


View solution in original post

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If the variable is for the current ritm, you could do something like:



var variableName = 'varName'; //you would pull this dynamically from your table


var variableValue = current.variables[variableName];


Thanks Brad. Worked Perfectly.


Thank you.

All of the articles older than this have people trying to use the "illegal" eval to try to handle this situation. Everyone needs to click "Helpful" on this.