HOw to display incident on map location

wakespirit
Kilo Guru

Dear all,

I need to build on ServiceNow mobile a page in which I have :

A list of Incident which has the GPS position in which it has been identified
When user select an Incident, I need to display it on google maps as part of my Incident view ( I do not want to display a new page)

Any idea how to approach this ?

regards

9 REPLIES 9

Akash4
Kilo Sage
Kilo Sage

Hello,

As per your requirement, the primary case i.e., showing a google map with all incidents of your interest to be displayed on Map Page. For which the steps would be:

1. Enable Maps API Key: You can create a google cloud account and activate Maps in google console, the steps would be simple following google docs.

2. A new API key would be generated form your step 1, which can be used at System Properties > Google Maps > "Map key from Google, tied to the URL of the server" > paste your key

3. Create or edit a Map Page from System UI > Map Page > (here editing 'Critical incidents' Page) You can filter based on your interest, the priority = 1 is the default case in this example.

var gr = new GlideRecord("incident");
gr.addQuery('priority', '1');
gr.addActiveQuery();
gr.query();
while (gr.next()) {
	if(gr.location.latitude && gr.location.longitude){
	   var item = map.addItem(gr);
	   item.latitude = String(gr.location.latitude);
	   item.longitude = String(gr.location.longitude);
	   item.dialog_title = gr.getDisplayValue();
	   item.icon = "https://maps.google.com/mapfiles/kml/pal3/icon51.png";
	   item.icon_width = "32";
	   item.icon_height = "32";
	}
}

4. We drive the maps from user table, which is the best way to display the location map in any task record (incident, change, catalog task etc.,) For this you can map each user to a particular location and in the location record, make sure you notice latitude and longitude as a basic requirement.

5. You can link this Map Page as a module or UI Action on the incident form in Navigation view or mobile view based on your requirement. This is done by creating a module - select a Link type of URL (from Arguments:), enter the URL = map_page.do?sysparm_name=<map page name>(in our case this is map_page.do?sysparm_name=Critical incidents)

The output could be seen as below: I created a new user from Hyderabad location, hence is the display focusing on 1 particular locaiton.

find_real_file.png

Hope this gives you some insights, let me know if you get stuck anywhere.

Regards, Akash

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

Thanks for your answer.

The POC is that a BUS driver will create an incident in case he has trouble with his bus.
During Incident creation I need to retrive the GPS location of the mobile in order to add LAT and LONG in Incident record

Then when the manager receive the event he can see at this point the location of the Incident on the map

How can I retrive first the mobile GPS when creating the Incident and past those GPS info in a Incident field ?

regards

This scenario needs advanced scripting in the Map Page and thorough knowledge on Geo Location tacking. You must activate the geolocation tracking plugin for this and enable for all of the bus driver mobile views.

As a first step, write a script for all bus driver user profile to activate. In the default view of the User form, select the 'Geolocation tracked' check box to enable agent location tracking while they create incidents or other records. Further this location could be stored on incident table and can be used at google map page that we created earlier.

This would be a crude idea, but you may surf things and sort them out, I could help you on the scripting part. Thanks, Akash

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

what do you mean by "write a script for all bus driver user profile to activate" ?