locked
FetchXML RRS feed

  • Question

  • Hey all,
    As a newbie to developing I would like some help with fetchXML

    Code below works, but I do not now how to show the attribute "fullname" in my Console.WriteLine statement.

    the attribute comes from a linked entity (systemuser)

    thanks for helping



    public

     

    static void GetAccountManagers(CrmService service)

    {

     

    string fetchXml = @"

    <fetch mapping=""logical"">

    <entity name=""ktn_accountmanager"">

    <attribute name=""ktn_name""/>

    <attribute name=""ktn_accountmanageruserid""/>

    <link-entity name=""systemuser"" from=""systemuserid"" to=""ktn_accountmanageruserid"" >

    <attribute name=""fullname""/>

    <filter type=""and"">

    <condition attribute=""fullname"" operator=""eq"" value=""Debrouwere, Edwin""/>

    </filter>

    </link-entity>

    </entity>

    </fetch>"

     

    ;

     

    String resultXml = service.Fetch(fetchXml.ToString());

    System.Xml.

    XmlDocument myXmlDocument = new System.Xml.XmlDocument();

    myXmlDocument.LoadXml(resultXml);

    System.Xml.

    XmlNodeList myNodeList = myXmlDocument.GetElementsByTagName("ktn_name");

     

     

    Console.WriteLine("\nGetAccountManagers found {0} contacts\n", myNodeList.Count);

     

    Console.ReadKey();

     

    foreach (System.Xml.XmlNode myNode in myNodeList )

    {

     

    Console.WriteLine("Contact fulname = {0} - {1}", myNode.InnerText, "????????????");

    }

     

    Console.ReadKey();

    }

    Wednesday, August 12, 2009 11:09 AM

Answers

All replies

  • Hi.

    Could you paste here XML you retrieve?
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Wednesday, August 12, 2009 11:11 AM
    Moderator
  • Contact fulname = BASF COATINGS AG  - ????????????
    Contact fulname = K&B HERMANN BUSCHKÖTTER  - ????????????
    Contact fulname = HORST GOEBEL  - ????????????
    Contact fulname = HECHT TECHNOLOGY GMBH  - ????????????
    Contact fulname = GEMMER MASCHINENBAU  - ????????????
    Contact fulname = RWE POWER  - ????????????
    Contact fulname = EMT GMBH  - ????????????
    Contact fulname = BLEDINA  - ????????????
    Contact fulname = Debrouwere, Edwin  - ????????????
    Contact fulname = UMICORE  - ????????????
    Contact fulname = BIONERGA NV  - ????????????
    Contact fulname = FENZI BELGIUM  - ????????????
    Contact fulname = DE SMET BALLESTRA  - ????????????
    Contact fulname = SOLUTIA EUROPE NV  - ????????????
    Contact fulname = NITTO EUROPE N.V.  - ????????????
    Contact fulname = FUJIFILM MANUFACTORING EUROPE BV  - ????????????
    Contact fulname = CHEMBO S.A.  - ????????????
    Contact fulname = BEAULIEU N.V.  - ????????????
    Contact fulname = BERRY YARNS  - ????????????
    Contact fulname = SUNALLOMER LTD  - ????????????
    Contact fulname = SPC  - ????????????
    Contact fulname = GE PLASTICS EUROPE B.V.  - ????????????
    Contact fulname = DU PONT DE NEMOURS  - ????????????
    Contact fulname = DU PONT SPANJE  - ????????????
    Contact fulname = EASTMAN CHEMICALS BV  - ????????????
    Contact fulname = TEIJIN TWARON BV  - ????????????
    Contact fulname = DUYVIS MACHINEFABRIEK B.V.  - ????????????
    Contact fulname = TAKENAKA MAASTRICHT  - ????????????
    Contact fulname = Debrouwere, Edwin  - ????????????
    Contact fulname = TECHNICOLOR DISTRIBUTION SERVICES LTD  - ????????????
    Contact fulname = KIASMA  - ????????????
    Contact fulname = LIUFENG MACHINERY INDUSTRY CO.,LTD.  - ????????????
    Contact fulname = BERRY YARNS  - ????????????
    Contact fulname = LOGISTICS ENGINEERING CONTRACTORS  - ????????????
    Contact fulname = DSM RESINS BV  - ????????????
    Wednesday, August 12, 2009 11:14 AM
  • I have used function in the past to retrive the node value from fetch XML ..following is the code for this...first perameter is the full result XML ( so resultXml in your code) ..and second perameter is field name ( fullname in your example)...


    hope this helps...
            /// <summary>
            /// Get field value from fetch XML string
            /// </summary>
            /// <param name="xml">fetch xml string</param>
            /// <param name="fieldName">The field name for the value to be returned</param>
            /// <returns></returns>
            public string GetFieldFromFetchXML(string xml, string fieldName)
            {
                try
                {
    
                    // Convert the XML to a Document
                    XmlDocument temp = new XmlDocument();
                    temp.LoadXml(xml);
    
                    // Set the document namespaces
                    XmlNamespaceManager nsmgr = new XmlNamespaceManager(temp.NameTable);
                    nsmgr.AddNamespace("q", "http://schemas.microsoft.com/crm/2006/WebServices");
    
                    // Get the Results Node
                    XmlNode nodeId = temp.SelectSingleNode("/resultset", nsmgr);
    
                    string returnString = "";
    
                    // Link the Survey Id
                    foreach (XmlNode result in nodeId)
                    {
    
                        // get the info from the template questions
                        returnString = result.SelectSingleNode(fieldName, nsmgr).InnerText;
                    }
    
                    return returnString;
                }
                catch (Exception ex)
                {
                    return string.Empty;
                }
            }
    
    Wednesday, August 12, 2009 12:08 PM
  • Hi, Edwin.

    It seems that you haven't inserted xml in correspond way... To insert xml to be readable use button on panel -

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Wednesday, August 12, 2009 5:25 PM
    Moderator