By Proximity

Suppose you want to search using proximity. For this, we have created the custom action with name “Inogic.Maplytics.API.Proximity” (ikl_InogicMaplyticsAPIProximity).

Custom action accepts following parameters:

  • CurrentLocation: Location for which you want to do the proximity search.

  • Proximity: Provide the proximity radius. e.g., 3. If you want to do Concentric Proximity search, then specify multiple proximity radii separated by comma ‘,’. For example, 5, 10, 15.

  • DistanceUnit: Provide the radius unit. It can be either “mile or kilometer". If the unit is not specified then by default mile will be considered as the radius unit.

  • Records: EntityCollection

  • Entity: Provide the entity name. e.g. “Account"

  • ViewName: Specify the view name. e.g., “My Active Accounts”

When user passes the required parameters and executes this action then it will return records colle

Note: As custom action has 2 minutes timeout so maximum records that are processed is around 90K- 100K. If you have a view having records more than 100K then it may throw a timeout issue. So, make sure to enter the viewname of the view that has less then 100K records.

To execute proximity action using the C#, use the following code.

//create request object
string requestName = "ikl_InogicMaplyticsAPIProximity";

                    //create request object
                    OrganizationRequest orgReq = new OrganizationRequest(requestName);
                    //for proximity
                    orgReq["CurrentLocation"] = "New York";
                    orgReq["Proximity"] = "10,25";
                    orgReq["DistanceUnit"] = "Mile";
                    //Entity & view
                    orgReq["Entity"] = "account";
                    orgReq["ViewName"] = "My Active Accounts";
                    OrganizationResponse response = service.Execute(orgReq);

                    EntityCollection recordsCollection = (EntityCollection)response.Results["RecordsCollection"];

To execute the action using the javascript (web api) you can use following code.

function executeCustomAction() {
    try {

        var actionObj = {
            CurrentLocation: "New York",
            Proximity: "10,25",
            DistanceUnit: "Mile",          
            Entity: "account",
            ViewName: "My Active Accounts",

        // call this function to execute the action 
       execute(actionObj, "ikl_InogicMaplyticsAPIProximity()", function (data) {

            alert("Success: " + data);

        }, function (error) {
            alert("Error: " + error.message);

    } catch (e) {

function execute(req, reqName, successCallback, errorCallback) {

    //create AJAX request
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: encodeURI(getWebAPIPath() + reqName),
        data: window.JSON.stringify(req),
        beforeSend: function (xhr) {
            //Specifying this header ensures that the results will be returned as JSON.             
            xhr.setRequestHeader("Accept", "application/json");
            //xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            xhr.setRequestHeader("OData-MaxVersion", "4.0");
            xhr.setRequestHeader("OData-Version", "4.0");
        success: function (data, textStatus, xhr) {
            //successCallback function
            if (data != null && data.value != undefined) {
            } else {
        error: function (xhr, textStatus, errorThrown) {


function getWebAPIPath() {
    return Xrm.Page.context.getClientUrl() + "/api/data/v8.0/";

Last updated