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)

Can one use a $filter when retrieving via GUID?

(0) ShareShare
ReportReport
Posted on by

I'm trying to find out if I can always use a $filter expression even if I only have an object's raw GUID.

I know I can do stuff like:

.../AccountSet(guid'bdc0e823-4f8e-e511-80e0-00155d62e31e')

to get the object but it would be helpful (for designing a user config system) if we could use a $filter to identify the object as an alternative.

.../AccountSet?$filter=<some_member_field> eq <some_guid>

It's a little frustrating to have to support two ways of identifying records to retrieve.

Any info on this area much appreciated!

Thx

PS: I guess I'm kind of asking if every Dynamics entity has an implicit "SelfId" property/field which is always present and which we can refer to in a $select expression.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    kyleknab Profile Picture
    517 on at

    Hi KorporalKernel,

    Yes you can use the "eq guid'<guid>' syntax in your $filter parameter.
    When filter by an entity's primary key field (e.g. AccountId for AccountSet) then you can just do $filter=AccountId eq guid'<guid>'.

    When you're comparing a lookup field on an entity to a guid, you must include /Id to indicate you're comparing the Id member of the lookup array.  For example, to filter AccountSet by the account's primarycontactid field:

  • Community Member Profile Picture
    on at

    OK Thanks, much appreciated.

    So does every object have a named primary key field? I've been perusing the returned JSON from a load of test REST queries and it's not very clear to me.

    Thanks

  • Community Member Profile Picture
    on at

    (Also your post was truncated where you were about to show an example of /Id).

    Thx

  • Suggested answer
    kyleknab Profile Picture
    517 on at

    In CRM every entity has a named primary key field; accounts have an accountid, Contacts have a contactid, etc.  And every lookup field on a CRM entity holds a GUID that corresponds to the primary key field on the entity type that is being looked up (account.primarycontactid : contact.contactid).

    Here is the example that was supposed to be on that reply:

    $filter=PrimaryContactId/Id eq 'guid<guid>'

  • Community Member Profile Picture
    on at

    Thanks a lot for these helpful explanations, much appreciated. So may I ask another question.

    Is the named primary key field that's always present a GUID string? From the examples I'm seeing here on a test system it's true.

    But could someone define a primary key field that isn't a GUID string but say an int, a string etc.

    Thanks

  • kyleknab Profile Picture
    517 on at

    CRM controls the primary key field and its always a GUID.

    Someone could certainly create a new field on an entity (or use an existing field), and say it will be a primary key, in which case they should  also construct a way (e.g. a custom workflow/plugin/JavaScript) to ensure the uniqueness of the data in that pseudo-primary key field.

    This is common for the OOTB Account Number field.  CRM does not enforce uniqueness on this field, but in practice you might keep this data clean (readable, 5-7 characters) and unique because it may integrate with some third party system that cannot be expected to replicate CRM's own GUIDs (e.g. your ERP).

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