- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 01:24 AM
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 ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 02:45 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 01:40 AM
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'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 02:45 AM
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();