locked
CRM 4 - FetchXML Count attribute RRS feed

  • Question

  • How to set the "count" (to restrict records display in the view for paging) in FetchXML... We tried all the possible ways but not able to limit the records... What should be the Minimum value that can be assigned? We have to restrict 3 records per page.

    Sample code
    FetchXml=@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='3'>
            <entity name='phonecall'>
            <attribute name='subject'/>
            <attribute name='regardingobjectid'/>
            <attribute name='scheduledend'/>
            <attribute name='scheduledstart'/>
            <attribute name='ers_callstatus'/>
            <attribute name='activityid'/>                           
            <order attribute='scheduledend' descending='true'/>
            </entity>
         </fetch>";

    Friday, March 28, 2008 2:10 PM

Answers

  • Hi.

     

    Here is a sample Xml HTTP Request. The value in the soap envelope is a fetch that returns a single row out of 3 available on my system.

     

    var soap = '<?xml version="1.0" encoding="utf-8" ?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">' + GenerateAuthenticationHeader() + '<soap:Body><Fetch xmlns="http://schemas.microsoft.com/crm/2007/WebServices"><fetchXml>&#60;fetch version&#61;&#34;1.0&#34; output-format&#61;&#34;xml-platform&#34; mapping&#61;&#34;logical&#34; distinct&#61;&#34;true&#34;&#62;&#60;entity name&#61;&#34;role&#34;&#62;&#60;attribute name&#61;&#34;name&#34;&#47;&#62;&#60;attribute name&#61;&#34;businessunitid&#34;&#47;&#62;&#60;attribute name&#61;&#34;roleid&#34;&#47;&#62;&#60;order attribute&#61;&#34;name&#34; descending&#61;&#34;false&#34;&#47;&#62;&#60;link-entity name&#61;&#34;systemuserroles&#34; from&#61;&#34;roleid&#34; to&#61;&#34;roleid&#34; visible&#61;&#34;false&#34; intersect&#61;&#34;true&#34;&#62;&#60;link-entity name&#61;&#34;systemuser&#34; from&#61;&#34;systemuserid&#34; to&#61;&#34;systemuserid&#34; alias&#61;&#34;aa&#34;&#62;&#60;filter type&#61;&#34;and&#34;&#62;&#60;condition attribute&#61;&#34;systemuserid&#34; operator&#61;&#34;eq-userid&#34;&#47;&#62;&#60;&#47;filter&#62;&#60;&#47;link-entity&#62;&#60;&#47;link-entity&#62;&#60;&#47;entity&#62;&#60;&#47;fetch&#62;</fetchXml></Fetch></soap:Body></soap:Envelope>';

     

          var Url = "/mscrmservices/2007/CrmService.asmx";

          var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

                xmlHttpRequest.Open("POST", Url , false);

                xmlHttpRequest.setRequestHeader("SOAPAction"," http://schemas.microsoft.com/crm/2007/WebServices/Fetch");

                xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

                xmlHttpRequest.setRequestHeader("Content-Length", soap.length);

                xmlHttpRequest.send(soap);

          var resultXml = xmlHttpRequest.responseXML;

                alert(resultXml.xml);

     

    As you can see the fetchXml is encoded, here is the fetch before I encode it.

     

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" page="1" count="1"><entity name="account"><attribute name="name"/><attribute name="accountid"/><attribute name="telephone1"/><filter type="and"><condition attribute="name" operator="like" value="A&#37;"/></filter></entity></fetch>

     

    page="1" count="1" and it works...

     

    Cheers,

    Adi

     

     

     

    Friday, April 4, 2008 4:39 PM

All replies

  • Hi.

     

    Sometimes its good to be wrong, the count does limit the number of records , you also need to add the page attibute.

     

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" page="1" count="1">...</fetch>

     

    Cheers,

    Adi 
    Friday, March 28, 2008 4:26 PM
  • Oh my goodness...  Better I have to leave it for the time being... Anyhow once again thanks for the info Adi....
    Saturday, March 29, 2008 9:37 AM
  •  

    I Changed to post...

    Thursday, April 3, 2008 4:09 PM
  • Adi,

    It's not working... Duno why...
    Friday, April 4, 2008 2:40 PM
  • Hi.

     

    Here is a sample Xml HTTP Request. The value in the soap envelope is a fetch that returns a single row out of 3 available on my system.

     

    var soap = '<?xml version="1.0" encoding="utf-8" ?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">' + GenerateAuthenticationHeader() + '<soap:Body><Fetch xmlns="http://schemas.microsoft.com/crm/2007/WebServices"><fetchXml>&#60;fetch version&#61;&#34;1.0&#34; output-format&#61;&#34;xml-platform&#34; mapping&#61;&#34;logical&#34; distinct&#61;&#34;true&#34;&#62;&#60;entity name&#61;&#34;role&#34;&#62;&#60;attribute name&#61;&#34;name&#34;&#47;&#62;&#60;attribute name&#61;&#34;businessunitid&#34;&#47;&#62;&#60;attribute name&#61;&#34;roleid&#34;&#47;&#62;&#60;order attribute&#61;&#34;name&#34; descending&#61;&#34;false&#34;&#47;&#62;&#60;link-entity name&#61;&#34;systemuserroles&#34; from&#61;&#34;roleid&#34; to&#61;&#34;roleid&#34; visible&#61;&#34;false&#34; intersect&#61;&#34;true&#34;&#62;&#60;link-entity name&#61;&#34;systemuser&#34; from&#61;&#34;systemuserid&#34; to&#61;&#34;systemuserid&#34; alias&#61;&#34;aa&#34;&#62;&#60;filter type&#61;&#34;and&#34;&#62;&#60;condition attribute&#61;&#34;systemuserid&#34; operator&#61;&#34;eq-userid&#34;&#47;&#62;&#60;&#47;filter&#62;&#60;&#47;link-entity&#62;&#60;&#47;link-entity&#62;&#60;&#47;entity&#62;&#60;&#47;fetch&#62;</fetchXml></Fetch></soap:Body></soap:Envelope>';

     

          var Url = "/mscrmservices/2007/CrmService.asmx";

          var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

                xmlHttpRequest.Open("POST", Url , false);

                xmlHttpRequest.setRequestHeader("SOAPAction"," http://schemas.microsoft.com/crm/2007/WebServices/Fetch");

                xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

                xmlHttpRequest.setRequestHeader("Content-Length", soap.length);

                xmlHttpRequest.send(soap);

          var resultXml = xmlHttpRequest.responseXML;

                alert(resultXml.xml);

     

    As you can see the fetchXml is encoded, here is the fetch before I encode it.

     

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" page="1" count="1"><entity name="account"><attribute name="name"/><attribute name="accountid"/><attribute name="telephone1"/><filter type="and"><condition attribute="name" operator="like" value="A&#37;"/></filter></entity></fetch>

     

    page="1" count="1" and it works...

     

    Cheers,

    Adi

     

     

     

    Friday, April 4, 2008 4:39 PM