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)

Convert EntityCollection to a xml string in the format of fetchxml result - crm 2011 onpremises

(0) ShareShare
ReportReport
Posted on by

Hi all, I have old  external webservice  which use fetchxml and get result in xml format.  (using very old way of connecting crm    "http://crmservername/mscrmservices/2007/crmservice.asmx" and organization name with token)

I need to upgrade this to use earlybound entity class and OrganizationServiceProxy  with crm 2011 organization service url . I have generate xrm.cs using CRMSvcUtil and other libraries. But there is no Fetch any more isn't it ?

so I have used RetrieveMultiple (new FetchExpression(fetchsrt)) 

now my question is how do I get this convert to string result in same format of fetchxml result.  So I don't need to change coding on applications that I am using this web service (as a gateway to handle crm data)

ideas pls

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi,

    You can use the ExecuteFetchRequest rather than RetrieveMultiple. This returns the results as fetchxml result xml.

    Hope this helps,

    Scott

  • Community Member Profile Picture
    on at

    Hi Scott , thanks but I found that it says this is deprecated in version 2011. and might not work for new versions .

    any other alternatives?

    anyway that's a shame this wonderful fetchxml option is no longer available in new versions ...

    is there anyway of serialization of entitycollection so I can get the result over a external web service to a web site.

  • Suggested answer
    Aileen Gusni Profile Picture
    44,524 on at

    HI,

    Just adding the Scott answer, if you still want to use RetrieveMultiple

    Not sure whether it is what do you want,

    You can use XmlElement Class

    EntityCollection fxResult1 = _orgService.RetrieveMultiple(new FetchExpression(fetchXml));

    // 4. create XML Document Object to put the set of fetchXML records

    XmlDocument xml = new XmlDocument();

    XmlDeclaration xmlDeclaration = xml.CreateXmlDeclaration("1.0", null, "yes");

    XmlElement root = xml.CreateElement("accounts");

    xml.InsertBefore(xmlDeclaration, xml.DocumentElement);

    xml.AppendChild(root);

    // 5. Foreach loop through the result and Build the XML node

    foreach (var e in fxResult.Entities)

    {

    XmlElement child_root_table = xml.CreateElement("Table1");

    root.AppendChild(child_root_table);

    XmlElement child_name = xml.CreateElement("name");

    child_name.InnerText = e.Attributes["name"].ToString();

    child_root_table.AppendChild(child_name);

    XmlElement child_accountid = xml.CreateElement("accountid");

    child_accountid.InnerText = e.Attributes["accountid"].ToString();

    child_root_table.AppendChild(child_accountid);

    XmlElement child_accountnumber = xml.CreateElement("accountnumber");

    child_accountnumber.InnerText = e.Attributes["accountnumber"].ToString();

    child_root_table.AppendChild(child_accountnumber);

    XmlElement child_creditonhold = xml.CreateElement("creditonhold");

    child_creditonhold.InnerText = e.Attributes["creditonhold"].ToString();

    child_root_table.AppendChild(child_creditonhold);

    }

    // 6. Convert to XML file and save in hard drive.

    string fetchXmlOutput = xml.OuterXml;

    StringReader xmlst = new StringReader(fetchXmlOutput);

    XmlDocument XDoc = new XmlDocument();

    XDoc.LoadXml(fetchXmlOutput.ToString());

    XDoc.Save(@"c:\\fetchxml-records.xml");

    source:

    prabirchoudhury.wordpress.com/.../dynamics-crm-2011-fetchxml-result-convert-to-xml-file

    Hope it helps.

    Thank you.

  • Community Member Profile Picture
    on at

    see I have a website  for customers (customer portal with many functions )  and  features to list customers orders , contacts , the services we are providing for them (some customise entities in CRM)

    this web service getting data using fetchxml and xml strings sending over webservice to web site, and there xml read and populate gridviews and so so.

    So I am trying to minimise the code changes of web site user controls  and just update webservice which get data from CRM.

    If I get the entitycollection and convert it to xml in the same format as current fetch does it time consuming . because I have to loop through my data twice  before display on web page.

    and my fetch xml queries not simple so if I use something like this mscrmbi.blogspot.co.uk/.../crm-2011-convert-entitycollection-to.html

    this is going to be a pain.

    I need to find out best and efficient way to do this.  I am having feeling that I will end up rewriting all my webservice methods as well as web site controls.

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi, The ExecuteFetchRequesf still works in CRM2013!

    If you want to serialise an EntitiyCollection to xml you could use the XmlSerializer class.

    Hope this helps,

    Scott

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