Display or Modify ritm variables from script

pbo
Mega Expert

Hi,

Is it possible to display or modify a selected ritm's variable from script (business rules).

Say we have a catalog item with one variable set containing variables var1, var2, var3.

I may use ritm.variables.var.getDisplayValue() syntax but I need a more generic approach because real variable set contains 100 variables.

I would like functions

      -   displayVariable(ritm, variable_name) to display the value of variable variable_name (equivalent to   ritm.variables.variable_name.getDisplayValue()

      -   setVariable(ritm, variable_name, variable_value) to set the value of variable variable_name to variable_value equivalent to ritm.variables.variable_name.setValue()

ritm.variables.getDisplayValue(variable_name) or ritm.variables.setValue(variable_name,variable_value) are not working

It seems that we may parse ritm variables using

for (key in ritm.variables) {

var v = ritm.variables[key];

}

(see https://community.servicenow.com/thread/145257)

but I need only one variable and this won't work to change the value

Any help ?

1 ACCEPTED SOLUTION

If variable var1 exists



ritm.variables.var1.getDisplayValue() --> Is correct



But


var variable_name='var1';


ritm.variables.variable_name.getDisplayValue() --> returns undefined


ritm.variables.getValue(variable_name)   --> returns undefined


ritm.variables.getDisplayValue(variable_name)   --> returns nothing



I found that


ritm.variables[variable_name].getDisplayValue());


and


ritm.variables[variable_name]


are both correct



For variable update I will use


ritm.variables[variable_name]=newValue,


ritm.update();


View solution in original post

2 REPLIES 2

anurag92
Kilo Sage

ritm.variables.variable_name.getDisplayValue() should work for displaying variable value (tried and tested )



And for setting value,



ritm.variables.variable_name = 'value of variable'


If variable var1 exists



ritm.variables.var1.getDisplayValue() --> Is correct



But


var variable_name='var1';


ritm.variables.variable_name.getDisplayValue() --> returns undefined


ritm.variables.getValue(variable_name)   --> returns undefined


ritm.variables.getDisplayValue(variable_name)   --> returns nothing



I found that


ritm.variables[variable_name].getDisplayValue());


and


ritm.variables[variable_name]


are both correct



For variable update I will use


ritm.variables[variable_name]=newValue,


ritm.update();