We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Update location field on incident

Evan2
Kilo Guru

Hi All

on incidents list view location is empty for many incidents. So i tried to set it as caller's location. For that I have written a background script like below to update initially a single record-

var inc = new GlideRecord('incident');
inc.addEncodedQuery('numberSTARTSWITHINC0539431');
inc.query();
while(inc.next){
inc.location=inc.caller_id.location;
inc.update();
inc.setWorkflow(false);
inc.autoSysFields(false);
}

 

 

But the request gets timed out and instance became unavailable after few minutes. So can anyone helpme how do I update location field in bulk for incidents.

 

Regards,

K Nandan

10 REPLIES 10

Hey,

This is just a generic service interruption scree..

You have to wait for some time until your instance is restored.

Best Regards
Aman Kumar

Every time I am running the query it leads to this page without updating the location to any single record.

 

Regards,

K Nandan

 

Create a fix script, you can find that in the application navigator:

Paste your script in the script section

Click on "Run Fix script"

Then, click on proceed in background, it should work fine

find_real_file.png 

Best Regards
Aman Kumar

Mahesh23
Mega Sage

Hi,

Try below code

var inc = new GlideRecord('incident'); inc.addEncodedQuery('numberSTARTSWITHINC0539431');

inc.query();

while(inc.next()){

inc.location=inc.caller_id.location; inc.setWorkflow(false);

inc.autoSysFields(false);

inc.update();

 

If you want to update multiple records where location is empty you can try below code.

var inc = new GlideRecord('incident');
inc.addEncodedQuery('locationISEMPTY');

inc.query();

while(inc.next()){

inc.location=inc.caller_id.location; inc.setWorkflow(false);

inc.autoSysFields(false);

inc.update();
}

 

}

Ankur Bawiskar
Tera Patron

Hi,

try to run for few records and verify and then run for all records

var inc = new GlideRecord('incident');
inc.addEncodedQuery('locationISEMPTY');
inc.setLimit(5); // comment this later on
inc.query();
while (inc.next()){
    inc.location = inc.caller_id.location;
    inc.setWorkflow(false);
    inc.autoSysFields(false);
    inc.update();
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader