Comments on: Open Google Map from a Location Record https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/ ServiceNow Consulting Scripting Administration Development Tue, 28 May 2024 19:32:23 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Mark Stanger https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/#comment-9522 Fri, 17 Mar 2017 12:11:29 +0000 https://servicenowguru.wpengine.com/?p=4910#comment-9522 In reply to Jyoti Landage.

You’re welcome. The problem here is that UI macros of any sort are not supported in the mobile app. I’m not sure what to do there other than suggest you request that ServiceNow supports UI macros (or something similar to reference field decorations) in the mobile interface.

]]>
By: Jyoti Landage https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/#comment-9521 Fri, 17 Mar 2017 10:32:30 +0000 https://servicenowguru.wpengine.com/?p=4910#comment-9521 Hi Mark,
Thanks for script!.. I want to Open Google Map from a Location Record in Mobile device. I want to implement same functionality on the mobile device. Any Help will be Appreciated.

]]>
By: Ankit Gupta https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/#comment-9520 Fri, 17 Mar 2017 05:56:33 +0000 https://servicenowguru.wpengine.com/?p=4910#comment-9520 It is not working on mobile app

]]>
By: Mark Stanger https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/#comment-9519 Fri, 18 Dec 2015 22:36:15 +0000 https://servicenowguru.wpengine.com/?p=4910#comment-9519 In reply to One Issue.

It’s probably a naming conflict. Because you’ve got 2 macros using similar code on the same form, you need to make sure all of the functions and variables in your script have unique names. Otherwise they will conflict with each other and you’ll end up with unpredictable results.

]]>
By: One Issue https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/#comment-9518 Fri, 18 Dec 2015 22:28:50 +0000 https://servicenowguru.wpengine.com/?p=4910#comment-9518 In reply to Perfect solution for Fuji.

So I have a user reference field that I am applying the same solution to two different macros. It seems that the first macro in the ref_contributions list has some strange behavior. When it’s a new form, it shows. When I clear the value, it works as expected, but when I add a new value, the first macro does not reappear, though the second does. Any ideas?

]]>
By: Mark Stanger https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/#comment-9517 Fri, 18 Dec 2015 22:05:02 +0000 https://servicenowguru.wpengine.com/?p=4910#comment-9517 In reply to Perfect solution for Fuji.

Thanks! The UI macro code itself is all rendered and executed at the same time the form loads. As such, it can evaluate the current value of the field when the form loads and display the macro accordingly. If you want to change the macro or take other actions as the field changes then you need to include the appropriate client-side code (included in script tags). The ‘Configuration item’ reference field macro is a good example of doing this out-of-box.

]]>
By: Perfect solution for Fuji https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/#comment-9516 Fri, 18 Dec 2015 21:55:04 +0000 https://servicenowguru.wpengine.com/?p=4910#comment-9516 In reply to Mark Stanger.

Thanks again Mark for sharing this solution. I don’t think I could have solved this one alone. Going to have to read into GlideEventHandler and how that works, seems useful.

I found a community article asking a similar question so I shared your solution (with a credit/link to snguru):
https://community.servicenow.com/message/858503

We figured out how to modify the ui macro image in Fuji, but it wouldn’t go away if there was no value in the reference field. Can you explain why this extra code is necessary (in terms of hiding the icon when no value is in the field).

]]>
By: Mark Stanger https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/#comment-9515 Mon, 13 Jul 2015 14:17:58 +0000 https://servicenowguru.wpengine.com/?p=4910#comment-9515 In reply to Ravish Rawat.

It should, but there might be some small changes to be made depending on your setup. This UI macro code works great in the Fuji instance I’ve been working in.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
   <g:evaluate var="jvar_guid" expression="gs.generateGUID(this);" />
   <j:set var="jvar_n" value="open_google_map${jvar_guid}:${ref}"/>

   <g2:evaluate var="jvar_show_google_map_display" jelly="true">
      var id = __ref__.getSysIdValue();
      if (id == null)
         "none";
      else {
         var loc = new GlideRecord('cmn_location');
         loc.get(id);
         if ((!loc.street.nil() $[AND] !loc.city.nil()) || (!loc.latitude.nil() $[AND] !loc.longitude.nil()))
            "";
         else
            "none";
      }
   </g2:evaluate>

   <a>
      <span id="${jvar_n}" onclick="openGoogleMap('${ref}')"
		  class="btn btn-default" 
		  title="${gs.getMessage('Open a Google Map for this location')}" 
		  alt="${gs.getMessage('Open a Google Map for this location')}"
		  style="display:$[jvar_show_google_map_display]; margin-right: 5px">
         <img border="0" src="https://maps.gstatic.com/favicon2.ico" height="13" width="13"/>
	  </span>
   </a>

   <script>
      needsRefreshLoc = false;
      function onChange_location_show_google_map(element, original, changed, loading) {
         var s = '${ref}'.split('.');
         var referenceField = s[1];
         if (needsRefreshLoc == false) {
            needsRefreshLoc = true;
            return;
         }
         if (changed.length == 0) {
            $('${jvar_n}').hide();
            return;
         }
         var locRec = g_form.getReference(referenceField, locationGoogleMapReturn);
      }
      
      function locationGoogleMapReturn(locRec) {
         var e = $('${jvar_n}');
         if ((locRec.street $[AND] locRec.city) || (locRec.latitude $[AND] locRec.longitude))
            e.show();
         else
            e.hide();
      }
      
      //Event.observe(g_form.getControl(${ref}.split('.')[1]), 'change', onChange_cmn_location_show_google_map);
      var l = new GlideEventHandler('onChange_location_show_google_map', onChange_location_show_google_map, '${ref}');
      g_event_handlers.push(l);

      //Pop open google maps window of location specified
      //URL should follow this format...http://maps.google.com/?q=1200 Pennsylvania Ave SE, Washington, District of Columbia, 20003

      function openGoogleMap(reference) {
         var s = reference.split('.');
         var referenceField = reference.substring(s[0].length+1);
         var sysId = g_form.getValue(referenceField);
         //Retrieve the 'Location' record
         var gr = new GlideRecord('cmn_location');
         gr.get(sysId);

         //Create and display the Map URL
         var mapURL = "http://maps.google.com/?q=";
         //Try location and city
         if(gr.street $[AND] gr.city){
            mapURL = mapURL + gr.street + ',' + gr.city + ',' + gr.state + ',' + gr.zip + ',' + gr.country;
         }
         //Else try latitude and longitude
         else if(gr.latitude $[AND] gr.longitude){
            mapURL = mapURL + gr.latitude + ',' + gr.longitude;
         }
	 //Strip '#' symbols to avoid encoding errors
	 mapURL = mapURL.replace(/#/g, "");
         window.open(mapURL);
      }
   </script>
</j:jelly>
]]>
By: Ravish Rawat https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/#comment-9514 Mon, 13 Jul 2015 13:52:52 +0000 https://servicenowguru.wpengine.com/?p=4910#comment-9514 Does this works on Fuji also because i tried and it is not working ???

Anyone able to do this on fuji ??

]]>
By: Mark Stanger https://servicenowguru.com/ui-actions-system-ui/open-google-map-location-record/#comment-9513 Tue, 02 Sep 2014 12:56:44 +0000 https://servicenowguru.wpengine.com/?p=4910#comment-9513 In reply to Martin S.

Thanks Martin! Google keeps changing their favicon location, hopefully the one you gave me will last a bit longer. :)

]]>