- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 02:57 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 03:37 AM - edited 10-13-2023 03:39 AM
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);
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 03:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 03:09 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 03:32 AM
@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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 03:40 AM
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.