Get variable value on server side script (not display value)

Eli Guttman
Tera Guru

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?

9 REPLIES 9

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!

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));

        }
    }
}



Harsh Vardhan
Giga Patron

try now.

 

gs.print(req.variables.getValue('model')); 

Ashutosh Munot1
Kilo Patron
Kilo Patron

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

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.