Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How can I make a "Show on map" button that will show the location of an incident on a map?

Terje Monsen1
Giga Contributor

We are using ServiceNow for IT service management, and we support a number of vessels. We have made an integration so that the lat/lon of the vessels are automatically updated.

Since the vessels travel around the world it would be very helpful if we had a button next to the "Location" field in the Incident window called "Show on map". Clicking this button should open a pop-up with a map and a marker on the location lat/lon.

Looking at the Map pages, I am not sure how to pass a Location to a map page, and how to re-center the map around this location.

Any help with examples would be appreciated. Please note that I am not very adept with scripting so tea-spoon-mode would be appreciated.

 

1 ACCEPTED SOLUTION

Terje Monsen1
Giga Contributor

I was searching for UI Policy, when I should have been searching for UI Action. Once Erik Gardner pointed that out, I found this page:
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/open-google-map-location-record/

The Google Maps URL system has since changed, so for a proper lat/lon with zoom I had to try and fail until I ended up with:

mapURL = 'https://www.google.com/maps/place/'+ gr.latitude + ','+ gr.longitude + '/@'+ gr.latitude + ','+ gr.longitude + ',5z';

This made the correct lat/lon marker, centered and zoomed the map to the desired level.

 

Thank you for your help.

 

View solution in original post

3 REPLIES 3

Shusovit
Mega Expert

There is already a module called Critical incident map. You can explore that.

Please Hit Correct, ️Helpful, or ❣️Like depending on the impact of the response

Erik Gardner1
Giga Guru

Hi Terje,

I'm not sure how to generate a map with only the incident you are coming from but if you can settle on a map with a defined scope/query its much easier.

First you'll have to create a map page and script a query on what you want to show up on the map page. If I understand you correctly you have lat/lon info in your incident ticket which means the map page query script would be against the incident tabel. Ex:

 

var gr = new GlideRecord("incident");
gr.addEncodedQuery("active=true^cmdb_ciISNOTEMPTY"); //here is you search query
gr.query();

//looping through our query result
while (gr.next()) {
	if(gr.<your_lat_field> && gr.<your_lon_field>){
	   var item = map.addItem(gr);
	   item.latitude = String(gr.<your_lat_field>);
	   item.longitude = String(gr.<your_lon_field>);
	   item.dialog_title = gr.getDisplayValue();
	   item.icon_width = "32";
	   item.icon_height = "32";
	
}

 

Then you need to create a UI Action on the Incident form which when clicked directs you to the new map page. Preferably in a new tab.

 

ex an OnClick variant which just redirects you to the map url (which you can get get if you click Try It in the Map record: 

 

action.setRedirectURL (<your_map_url>);

Hope that helps!

Terje Monsen1
Giga Contributor

I was searching for UI Policy, when I should have been searching for UI Action. Once Erik Gardner pointed that out, I found this page:
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/open-google-map-location-record/

The Google Maps URL system has since changed, so for a proper lat/lon with zoom I had to try and fail until I ended up with:

mapURL = 'https://www.google.com/maps/place/'+ gr.latitude + ','+ gr.longitude + '/@'+ gr.latitude + ','+ gr.longitude + ',5z';

This made the correct lat/lon marker, centered and zoomed the map to the desired level.

 

Thank you for your help.