Convert sys ids to display value on string field for existing records

Rocky5
Kilo Sage

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.

1 ACCEPTED SOLUTION

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

View solution in original post

3 REPLIES 3

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Rocky ,

 

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

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.

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