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 365 | Integration, Dataverse...
Answered

Fetch XML to C# Array

(0) ShareShare
ReportReport
Posted on by

Hi All,

I have following fetch XML and I want to convert it to C# array or list. Can you help me please?

var fetchXml = $@"
<fetch top='2000'>
<entity name='opportunity'>
<attribute name='willis_opportunityid' />
<filter type='and'>
<condition attribute='willis_probability' operator='eq' value='{fetchData.willis_probability/*7*/}'/>
<condition attribute='willis_inceptiondate' operator='on-or-before' value='{fetchData.willis_inceptiondate/*01-25-2020*/}'/>
</filter>
</entity>
</fetch>";

I have the same question (0)
  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at

    Hi,

    please refer to this code snnipet from the doc:

    // Retrieve all accounts owned by the user with read access rights to the accounts and   
    // where the last name of the user is not Cannon.   
    string fetch2 = @"  
         
            
               
               
               
                  
                     
                  
               
            
        ";   
      
    EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(fetch2));
    foreach (var c in result.Entities)
    {
       System.Console.WriteLine(c.Attributes["name"]);
    }

    source: https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/use-fetchxml-construct-query

  • Community Member Profile Picture
    on at

    Hi Mehdi,

    I am getting error on _serviceProxy. That _serviceProxy does not found in current context. Could you help me ?

    Thanks,

    Mayur

  • meelamri Profile Picture
    13,216 User Group Leader on at

    Hi,

    Can you please share your code ?

  • Community Member Profile Picture
    on at

    Hi Mehdi,

    Following is my code:

    var fetchData = new

                   {

                       willis_probability = "7",

                       willis_inceptiondate = "01-25-2020"

                   };

                   var fetchXml = $@"

    <fetch top='50'>

     <entity name='opportunity'>

       <attribute name='willis_opportunityid' />

       <filter type='and'>

         <condition attribute='willis_probability' operator='eq' value='{fetchData.willis_probability/*7*/}'/>

         <condition attribute='willis_inceptiondate' operator='on-or-before' value='{fetchData.willis_inceptiondate/*01-25-2020*/}'/>

       </filter>

     </entity>

    </fetch>";

                   EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(fetchXml));

                   foreach (var c in result.Entities)

                   {

                       System.Console.WriteLine(c.Attributes["name"]);

                   }

    Do we need to define service proxy or any library we have to add?

  • Verified answer
    meelamri Profile Picture
    13,216 User Group Leader on at

    Ok, I understand now. Please refer to this blog: carldesouza.com/.../

    You will find all the steps, you need to add SDK assemblies, connect to your CRM to get your serviceProxy and so on.

    Good luck !

  • Community Member Profile Picture
    on at

    Hi Mehdi,

    It worked for me.

    Many Thanks,

    Mayur

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

#1
Martin Dráb Profile Picture

Martin Dráb 51 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans