- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 09:28 AM
Hello All.
One my first day working in Service Now, I added a custom reference field called "Club Name" (u_locationref_1) to the incident form.
I didn't realize at the time that there is some out of the box functionality built using the "location" field. We ended up with about 100k incidents where the "location" field is blank but the good news in I do have the values in my custom field.
I need a background script that will go in to every incident and copy the value of my "Club Name" (u_locationref_1) to the "Location" field and not send notifications or run BR's?
Once it's done, I will be able to delete the custom field and just use location.
Can any one help?
Thanks
Carl
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 09:31 AM
Hi Carl,
Here you go.
updateincidents();
function updateincidents()
{
var gr = new GlideRecord('incident');
//gr.addQuery('u_locationref_1ISNOTEMPTY'); add this line if you want to filter records i.e locationref is not empty
gr.query();
while(gr.next())
{
gr.location = gr.getValue('u_locationref_1');
gr.setWorkflow(false);
gr.autoSysFields(false);
gr.update();
}
}
Background Scripts — ServiceNow Elite

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 09:39 AM
@Carl,
Meanwhile you can run this script on DEV instance first and make sure everything is running fine.
If result looks good I would prefer you to run this on prod during non business hours.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 09:34 AM
Here you go
var gr= new GlideRecord("incident");
gr.addQuery('u_locationref_1','!=','');
gr,query();
while(gr.next()){
gr.autoSysFields(false); // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on
gr.setWorkflow(false); // Do not run any other business rules
gr.location=gr.u_locationref_1;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 09:37 AM
Uh oh. I don't know which is right...
Get Outlook for iOS<https://aka.ms/o0ukef>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 10:08 AM
If your issue is resolved, please mark it as correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2016 10:49 AM
Pradeep got this one...
All 3 of you, as always, came to my rescue and all had the right answer so I went with the first response.
I appreciate all of you and your time!
Thanks!
Carl