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

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

From server side scripts you can use 

current.variables.<variable name> // tjhis will give you the sys_id of value selected since it is a reference Variable
OR
current.variables.<variable name>.getDisplayValue() // tjhis will give you the Display Value of the selected value

 

From Client Side

g_form.getValue('<variable name>');// This will give you the sys_id of the selected Value
OR
g_form.getDisplayBox('<variable name>').value;// This will give you the Display value of the selected Value
-Anurag

@Anurag Tripathi i tried this but 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);

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