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

ideamax
Mega Expert

Hi Nandan,

1. How many records are present in the system where location is empty?

https://<instance_name>.service-now.com/incident_list.do?sysparm_query=location%3DNULL&sysparm_view=

 

Use the following script - 

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

grUpdateLocation.setUseEngines(false);
inc.update();

}

Please check if there are any mandatory fields set using data policy, to ignore those data policy you can use setUseEngines(false).