- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 07:23 AM
Hello Guys,
We used to have a reference field (user table) on catalog item from few years, And for some reason I had to change it to the string field. But, after changing to string field, On all the previous RITM records that variable value displays as sys id instead of display value. How can I fix it? how should be the script look like ?
Thanks,
Rocky.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 08:21 AM
var getRITM = new GlideRecord("sc_req_item");
getRITM.addQuery('sys_id','Write Sys ID of any RITM'); //For testing purpose
getRITM.query();
while (getRITM.next()) {
var getUser = new GlideRecord("sys_user");
getUser.addQuery("sys_id",getRITM.variables.name); //write proper variable name here from RITM user field
getUser.query();
if (getUser.next()) {
getRITM.name = getUser.name; //Write proper field name for RITM
getRITM.update();
}
}
Regards,
Gunjan
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 07:32 AM
Hi
You can give a try to below script :- Write it down in background script and first run for only one record by applying addQuery.
var getRITM = new GlideRecord("sc_req_item");
getRITM.query();
while (getRITM.next()) {
var getUser = new GlideRecord("sys_user");
getUser.addQuery("sys_id", getRITM.name); //write proper field name here from RITM user field
getUser.query();
if (getUser.next()) {
getRITM.name = getUser.name; //Write proper field name for RITM
getRITM.update();
}
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Gunjan Kiratkar
Consultant - ServiceNow, Cloudaction
Rising Star 2022
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 08:14 AM
Hello Gunjan,
This is not a field on RITM table but, a variable on request item (that is displayed on variable editor on RITM). Does gliding sc_req_item tabel will still work ? if so, What should be the addQuery statement ?
Thanks,
Rocky.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 08:21 AM
var getRITM = new GlideRecord("sc_req_item");
getRITM.addQuery('sys_id','Write Sys ID of any RITM'); //For testing purpose
getRITM.query();
while (getRITM.next()) {
var getUser = new GlideRecord("sys_user");
getUser.addQuery("sys_id",getRITM.variables.name); //write proper variable name here from RITM user field
getUser.query();
if (getUser.next()) {
getRITM.name = getUser.name; //Write proper field name for RITM
getRITM.update();
}
}
Regards,
Gunjan