web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How can I filter by distance to a given geo location?

(0) ShareShare
ReportReport
Posted on by 225

From the wiki here I should be able to filter on distance by 

$filter=geo.distance(location, geography'POINT(-122.131577 47.678581)') le 10

And I tried doing it with Javascript with no luck as JS has limits for the types of filters it can use. So I moved on to C#, but I'm stuck as I can see how the expression would look like. The documentation is a little poor, would be nice with an example but google ins't my friend. Anyways;

            var latitude = 25.075648;
            var longitude = 4.746094;

            QueryExpression qe = new QueryExpression()
            {
                EntityName = qi.EntityName,
                ColumnSet = new ColumnSet(qi.EntityColumns),
                TopCount = 5,
                Criteria =
                {
                    Filters =
                    {
                        new FilterExpression
                        {
                            FilterOperator = LogicalOperator.And,
                            Conditions =
                            {
                                // ???
                            }
                        }
                    }
                }
            };

The entity is msdyn_workorder and it has msdyn_latitude and msdyn_longitude. Has anyone created a filter in C# with distance and how did you do it?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I was doing similar functionality and you just can't build it using standard query.

    I was designing special action and plugin that handled message of that action. I'm afraid this is the only way for you.

  • _Lars_ Profile Picture
    225 on at

    You made a plugin to Dynamics that does requests and filtering på latitude and longitude?

    From the wiki i referenced, docs.microsoft.com/.../odata-expression-syntax-for-azure-search, one could clearly make these filters. But what are the system requirements for this? Azure Search is mentioned, what is that vs on premise?

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Lars,

    I saw your reference and it has nothing common with WebApi of CRM. CRM's WebApi implementation doesn't support mentioned operators. So as I mentioned before the only approach available for you is approach I mentioned in my initial reply.

    Good luck.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans