Get Value of variable

mregragui_ext
Tera Contributor

Hi,

I want to get the value of the "Select the software/system" and fill a field in the form of the RITM with this value.

variable value.png

2 ACCEPTED SOLUTIONS

Hi @mregragui_ext 

 

If you are using "gr.get()" , you need to use sys_id of that record

 

 

 

var mrvs;
var itemID = 'ab223sajnjsb7r3rr4t';   //set here sys_id of ritm record 
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
mrvs = ritmGR.variables.var1;
ritmGR.setValue('u_business_application',mrvs);
ritmGR.update();
}
gs.print(mrvs);

 

 

 

                                                     OR

 

Try this

 

var mrvs;
var itemID = "RITM0010246";  
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('number',itemID);
ritmGR.query();
if (ritmGR.next()) {
mrvs = ritmGR.variables.var1;
ritmGR.setValue('u_business_application',mrvs);
ritmGR.update();
}
gs.print(mrvs);

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

By the looks of it u_business_application is a reference field, it will only take the value of var1 if it is present on the table it references.

Can you add logs like below and show that values you get

var mrvs;
var itemID = 'RITM0010246';
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
gs.print('came here 1');
mrvs = ritmGR.variables.var1;
gs.print('mrvs  = '+ mrvs );
ritmGR.setValue('u_business_application',mrvs);
ritmGR.update();
}
gs.print(mrvs);

 

Once you get the value of mvrs, try to set the same thing on u_business_application on form and see if you can do it manually.

 

-Anurag

View solution in original post

12 REPLIES 12

@Vishal Birajdar i have tried this solution not working 

var mrvs;
var itemID = 'RITM0010246';
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
mrvs = ritmGR.variables.var1;
ritmGR.setValue('u_business_application',mrvs);
ritmGR.update();
}
gs.print(mrvs);

Hi @mregragui_ext 

 

If you are using "gr.get()" , you need to use sys_id of that record

 

 

 

var mrvs;
var itemID = 'ab223sajnjsb7r3rr4t';   //set here sys_id of ritm record 
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
mrvs = ritmGR.variables.var1;
ritmGR.setValue('u_business_application',mrvs);
ritmGR.update();
}
gs.print(mrvs);

 

 

 

                                                     OR

 

Try this

 

var mrvs;
var itemID = "RITM0010246";  
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('number',itemID);
ritmGR.query();
if (ritmGR.next()) {
mrvs = ritmGR.variables.var1;
ritmGR.setValue('u_business_application',mrvs);
ritmGR.update();
}
gs.print(mrvs);

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hey Mate,

If you are using "gr.get()" , you need to use sys_id of that record -> this will work with the number too

AnuragTripathi_0-1697193709997.png

 

AnuragTripathi_1-1697193728296.png

 

-Anurag

Hi @Anurag Tripathi 

 

Cool...!! I have not tried this with number...!! as its better to use "sys_id"

Thanks for this...!!!

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Thank you