Skip to content

Get Current Location of Device in D365 CE(CRM) using JavaScript

In this blog, we will look at how we can get the current location of the device with the click of a button.  

Implementation

Syntax:

Xrm.Device.getCurrentPosition().then(successCallback, errorCallback)

Code:

var formCustomizations = {
    getLocation: function (executionContext) {
        var formContext = executionContext;
        Xrm.Device.getCurrentPosition().then(
            function success(location) {
formContext.getAttribute("vv_latitude").setValue(location.coords.latitude);
formContext.getAttribute("vv_longitude").setValue(location.coords.longitude);
            },
            function (error) {
                Xrm.Navigation.openAlertDialog({ text: error.message });
            }
        );
    }
}
  • Call the “getLocation” function on button.
  • After doing everything successfully when you will click on a button you will get latitude and longitude.

NOTE:

  1. This method is supported only for mobile clients.
  2. Location setting must be enabled in Dynamics 365 for Phones app

Follow below steps to achieve this:

  • Go to settings
  • click on enable location
  • click on OK to give permission
  1. Dynamics 365 for Phones app must have the permission of Location in your mobile device.

5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments