Skip to main content

Notifications

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!

  • DynaMoX Profile Picture
    DynaMoX 15 on at
    RE: (PLUGIN/C#) Can we use Retrieve method to retrieve a record with a QueryExpression ?

    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
    Guido Preite 54,087 Super User 2024 Season 1 on at
    RE: (PLUGIN/C#) Can we use Retrieve method to retrieve a record with a QueryExpression ?

    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
    DynaMoX 15 on at
    RE: (PLUGIN/C#) Can we use Retrieve method to retrieve a record with a QueryExpression ?

    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
    Guido Preite 54,087 Super User 2024 Season 1 on at
    RE: (PLUGIN/C#) Can we use Retrieve method to retrieve a record with a QueryExpression ?

    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

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans