Background script to copy a value from one field to another.

carlh
Kilo Guru

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

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

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


View solution in original post

18 REPLIES 18

You will have to go with the time stamp on the response. He corrected his script later


It happens with all of us everytime in one or other thread


I agree. I was just kidding


Hahah I was starting to stress thinking you guys were seriously battling for the mark.



Thanks you guys. I have more easy ones coming soon…


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

"Proof that gamification works!" Ask the Expert: Community Etiquette, TechNow Ep 27