Update variable value using SetValue

Eli Guttman
Tera Guru

Hi,

i'm trying to update requested item variables using script. i tried to do it using the setValue function

Seems like this option work

req.variables.first_name = 'MY NAME';

but this option does not work:

req.setValue('variables.first_name ','MY NAME);

req.update();

Anyone know the reason or how i should use the setValue function for variables?

12 REPLIES 12

Lakshmaiah Dump
Giga Expert

Remove the variables and add   a script in catalog client Script. req.setValue('first_name ','MY NAME); PS:Hit like, correct, helpful when you feel happy.


Hi,



The script is not on the client side, but on server side.



I tried to remove the "variables" word like this:



req.setValue('first_name ','MY NAME);



but it's not working.


Lakshmaiah Dump
Giga Expert

If you use the server side then it's easy use the current object.
Ex:



Current.variables.first_name = "MY NAME";


OK, the only problem is that this is not dynamic, meaning, i'm using a script to update several variables, something like:



function updateVar (number,vaiable_name,value){


var var_name   = 'variables.' + vaiable_name;


var req = new GlideRecord('sc_req_item);


req.addQuery('number',number);


req.query();


if (req.next()){


req.setValue(var_name,value);


req.update();


}


}



using directr update does not allow me to do that, or maybe you are familiar with a way to do it?