Skip to main content

Notifications

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

  • kyleknab Profile Picture
    517 on at
    RE: Can one use a $filter when retrieving via GUID?

    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).

  • Community Member Profile Picture
    on at
    RE: Can one use a $filter when retrieving via GUID?

    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

  • Suggested answer
    kyleknab Profile Picture
    517 on at
    RE: Can one use a $filter when retrieving via GUID?

    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
    RE: Can one use a $filter when retrieving via GUID?

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

    Thx

  • Community Member Profile Picture
    on at
    RE: Can one use a $filter when retrieving via GUID?

    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

  • Suggested answer
    kyleknab Profile Picture
    517 on at
    RE: Can one use a $filter when retrieving via GUID?

    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:

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
dkrishna Profile Picture

dkrishna 6

Featured topics

Product updates

Dynamics 365 release plans