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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

(PLUGIN/C#) Can we use Retrieve method to retrieve a record with a QueryExpression ?

(0) ShareShare
ReportReport
Posted on by 15

Hi all, really fast question !

I have managed to get a filtered record by using RetrieveMultiple and by specifying my filtering criteria in a QueryExpression/FilterExpression.

It's working fine but I have the feeling that it must be a cleaner solution to archive this !

I don't need to retrieve more than one record, I just need to confirm that a record with value "x" in field "y" exist in my DB.

Can I do that with a simple Retrieve() ? 

Or in other words, what's the most proper way to do what I want to do ?

Thanks for help!

I have the same question (0)
  • DynaMoX Profile Picture
    15 on at

    Ok, so even with FetchXML I still need to declare an EntityCollection to get my record...

    Thank you for your help !

  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    in your scenario FetchXML is equivalent to a QueryExpression, with C# the code will be:

    service.RetrieveMultiple(new FetchExpression(fetchXMLquery));

    I hope you can find a "secret joker" but the platform for this component is the same in the last 13 years. You can try some tricks if the field can be an alternate key (so unique) and doing a retrieve by the alternate key.

  • DynaMoX Profile Picture
    15 on at

    I keep it open to see if eventually somebody have a "secret joker", but thank you anyway for your help! I will mark your answer as a solution if nobody can "find better" !

    PS: A friend have said to me that I could use directly a FetchXML in my code but we didn't had the time to go into details, if somebody know what he means and have an example, please don't wait for a special invitation before sharing your knowledge ;) Thanks

  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    if you need to check by a field value and not by ID, RetrieveMultiple is the only way.

    Retrieve requires the ID and it throws an exception if the record is not found, from this point doing a RetrieveMultiple is also better because you check the result Entities count (0, 1 or more than 1)

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

News and Announcements

Season of Giving Solutions is Here!

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 365 | Integration, Dataverse, and general topics

#1
whitebeard Profile Picture

whitebeard 68

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 66 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 40 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans