Get variable value on server side script (not display value)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 07:49 AM
Hi,
On business rule / workflow script - how can i get the value of a variable ( not display value, value)?
for example - variable named model
var req = new GlideRecord('sc_req_item');
req.addQuery('number','RITM0219702');
req.query();
if (req.next()){
gs.print(req.getValue('variables.model')); // this is not working - return null
gs.print(req.getDisplayValue('variables.model')); // this is working and return the display value
}
Anyone know the reason?
- Labels:
-
Scripting and Coding
-
Team Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2019 10:31 AM
Hi,
Unfortunately, I'm still not understanding.
Either way, to get the value of the variable, please use the method I listed above 5 days ago.
Take care!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 02:57 PM
I'm late to the party but I think you are looking for something more like this...
var current = new GlideRecord('sc_req_item');
if (current.get('number', 'RITM3722049')) {
//gs.print(current.number.toString());
for (var key in current.variables) {
if (current.variables.hasOwnProperty(key)) {
var v = {
name: key,
value: current.variables[key] + '',
display: current.getDisplayValue('variables.' + key)
};
gs.print(JSON.stringify(v));
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 07:55 AM
try now.
gs.print(req.variables.getValue('model'));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2019 04:37 AM
HI,
Use this script to get value of a variable on RITM:
var req = new GlideRecord('sc_req_item');
req.addQuery('number','RITM0219702');
req.query();
if (req.next()){
gs.print(req.variables.model);
gs.print(req.getDisplayValue('variables.model'));
}
So what Allen is trying to say is, even if you use above code which i posted will give you sys id of the model if reference field or value if other field.
Same you get using getValue method. You can use this value to compare the result from your table which you configured.
IT won't be an issue.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2019 12:36 AM
Hi,
Thank you, but this also does not solve the problem:
For this: gs.print(req.variables.model); - you can't pass the variable as a parameter
for this: gs.print(req.getDisplayValue('variables.model')) - you can pass is as a parameter to the getDisplayValue() function. i'm looking for the same thing but with the getValue() function.