Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Embed Map Pages to Case Task Form

Amit83
Tera Contributor

Hi Team,

 

I have created a map page to track Assigned To's location. How can I attach it to sn_customerservice_task form?

 

Regards,

Amit

1 ACCEPTED SOLUTION

Amit Pandey
Kilo Sage

Hi @Amit83 

 

As a workaround, would recommend you to create a UI Action with following script-

 

     var latSource = g_form.getValue('u_fe_last_latitude');
     var longSource = g_form.getValue('u_fe_last_longitude');

    var latDest = g_form.getValue('latitude');
    var longDest = g_form.getValue('longitude');

    var mapsUrl = 'https://www.google.com/maps/dir/?api=1&origin=' + latSource + ',' + longSource + '&destination=' + latDest + ',' + longDest + '&travelmode=driving';

    g_navigation.openPopup(mapsUrl);

This will open the Google Maps in a new window showing the route, eta and source and destination.

 

Please mark my answer helpful and correct.

 

Regards,

Amit

View solution in original post

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Amit83 

 

Need to create a new modules available in CSM_task table and in link type 

 

AGLearnNGrow_0-1709288311946.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG 

 

But how can I embed it to case task form? Also, if you could help me with any other alternatives for displaying map on case task form will work for me. I am using following map page script which is working fine-

var now_GR = new GlideRecord("sn_customerservice_task");
//now_GR.addQuery('sys_id', '3e8****833100');
now_GR.query();

while (now_GR.next()) {
    var item = map.addItem(now_GR);
    item.latitude = now_GR.u_parent.location.latitude.getDisplayValue(); // Latitude of the destination 
    item.longitude = now_GR.u_parent.location.longitude.getDisplayValue(); // Longitude of destination 
    item.icon = "http://maps.google.com/mapfiles/kml/pal3/icon51.png";
    item.icon_width = "32";
    item.icon_height = "32";

    var secondLocationItem = map.addItem(now_GR);
    secondLocationItem.latitude = now_GR.u_fe_last_latitude.getDisplayValue('u_fe_last_latitude'); // Latitude of the source location
    secondLocationItem.longitude = now_GR.u_fe_last_longitude.getDisplayValue('u_fe_last_longitude'); // Longitude of the source location
    secondLocationItem.icon = "http://maps.google.com/mapfiles/kml/pal3/icon32.png"; // Different icon for the second location
    secondLocationItem.icon_width = "32";
    secondLocationItem.icon_height = "32";

    // Draw a line connecting the two locations
    map.addLine(item, secondLocationItem);

    // Call Google Maps Directions API to get route information
    var directionsURL = "https://maps.googleapis.com/maps/api/directions/json" +
        "?origin=" + item.latitude + "," + item.longitude +
        "&destination=" + secondLocationItem.latitude + "," + secondLocationItem.longitude +
        "&key=AIzaSy*****dgO3fxwbd3UU"; // Replace YOUR_API_KEY with your actual Google Maps API key

    var response = new GlideHTTPRequest(directionsURL).get();
    var responseBody = response.getBody();
    var parsedResponse = new global.JSON().decode(responseBody);

    if (parsedResponse && parsedResponse.routes && parsedResponse.routes.length > 0) {
        var route = parsedResponse.routes[0];
        if (route && route.legs && route.legs.length > 0) {
            var leg = route.legs[0];
            var etaSeconds = leg.duration.value; // Duration in seconds
            var etaMinutes = Math.round(etaSeconds / 60); // Convert to minutes
            gs.info("Estimated Time of Arrival: " + etaMinutes + " minutes");
        }
    }
}

Dear @Amit83 

 

code is week area for me mate, what i know i shared mate.

 

@AshishKM any help. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

shwetanksingh
Kilo Guru

 

 

You cannot put Map page on case task form. Also, this is not possible in ServiceNow. I recommend either exploring the Field Service Management plugin or integration with 3rd party vendors.

Shwetank Singh
Service-now Consultant