locked
simle fetchXml query strange ERROR message RRS feed

  • Question

  • I try to filter a subgrid and i get this error which is not very helpful

    Could any one look at my fetchXml please and let me know what i am doing wrong

    Thanks

    function updateSubGrid() {
     
    //This will get the related products grid details and store in a variable.
     
    var relatedProducts = document.getElementById("Activities");
    
     //relatedProducts= related[0].id;
    //Initializing the lookup field to store in an array.
     
    var lookupfield = new Array;
     
    //Get the lookup field
     
    lookupfield = Xrm.Page.getAttribute("regardingobjectid").getValue();
     
    //This will get the lookup field guid if there is value present in the lookup
     
    if (lookupfield != null) {
     
    var lookupid = lookupfield[0].id;
     
    }
     
    //Else the function will return and no code will be executed.
     
    else {
     
    return;
     
    }
     
    //This method is to ensure that grid is loaded before processing.
     
    if (relatedProducts ==null )
     
    {
     
    //This statement is used to wait for 2 seconds and recall the function until the grid is loaded.
     
    setTimeout('updateSubGrid()', 4000);
     
    return;
     
    }
     
    
     
    
    var fetchXml  = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    fetchXml  += "<entity name='activitypointer'>";
    
    
    fetchXml  += "<order attribute='modifiedon' descending='false' />";
    
    
    fetchXml  += "<filter type='and'>";
    fetchXml  += "<filter type='or'>";
    fetchXml  +="<condition attribute='statecode' operator='eq' value='1' / >"
    fetchXml  +="<condition attribute='statecode' operator='eq' value='2' / >"
    
    fetchXml  += "</filter>";
    fetchXml  += "</filter>";
    
    fetchXml  += "</entity>";
    fetchXml  += "</fetch>";
    
    
    //Setting the fetch xml to the sub grid.
     
    relatedProducts.control.setParameter("fetchXml", fetchXml);
     
    //This statement will refresh the sub grid after making all modifications.
     
    relatedProducts.control.refresh();
     
    }

    please help 
    • Edited by _cram Monday, February 18, 2013 4:46 PM
    Monday, February 18, 2013 12:38 PM

Answers

  • Try this fetch query:-

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="activitypointer">
        <attribute name="activitytypecode" />
        <attribute name="subject" />
        <attribute name="statecode" />
        <order attribute="modifiedon" descending="false" />
        <filter type="and">
          <condition attribute="statecode" operator="in">
            <value>1</value>
            <value>2</value>
          </condition>
        </filter>
      </entity>
    </fetch>


    Regards Faisal

    • Marked as answer by _cram Monday, February 18, 2013 7:46 PM
    Monday, February 18, 2013 1:32 PM
  • Hi,

    Like that:

    <condition attribute="regardingobjectid" operator="eq" value='"+ Xrm.Page.data.entity.getId() + "' />

    One tip for generate FetchXml is doing what faisal refer, make a AdvancedFind a you can download de FetchXML, helps a lot.

    PS: Set faisal or my post or both as answer and\or useful.

    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful.

    Pedro Azevedo Crm Specialist 4.0\2011


    • Proposed as answer by Azevedo PedroMVP Monday, February 18, 2013 5:47 PM
    • Edited by Azevedo PedroMVP Monday, February 18, 2013 5:49 PM
    • Marked as answer by _cram Monday, February 18, 2013 7:45 PM
    Monday, February 18, 2013 5:47 PM

All replies

  • Hi,

    I found at least two problems:

    1. To retrieve all attributes put <all-attributes/> inside entity node.  Is not recommended do that.
    2. Why filter and inside a or? Put just or filter, delete and filter. Which query you want to do?
    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful.


    Pedro Azevedo Crm Specialist 4.0\2011

    Monday, February 18, 2013 1:30 PM
  • Try this fetch query:-

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="activitypointer">
        <attribute name="activitytypecode" />
        <attribute name="subject" />
        <attribute name="statecode" />
        <order attribute="modifiedon" descending="false" />
        <filter type="and">
          <condition attribute="statecode" operator="in">
            <value>1</value>
            <value>2</value>
          </condition>
        </filter>
      </entity>
    </fetch>


    Regards Faisal

    • Marked as answer by _cram Monday, February 18, 2013 7:46 PM
    Monday, February 18, 2013 1:32 PM
  • Hi

    Thanks for your replies

    Azevedo I have tryed what you said but it does not work . i am not exactly sure what to to with <all-attributes/> and how to put that inside the entity node.

    Faisal i have tryed your query and i still get the same error.

    Thank you

    Monday, February 18, 2013 1:58 PM
  • Thank you for your reply. As I have extracted this fetchxml from Advanced find therefore the issue will be with something else. You can copy the view which you are using the your grid. Edit filter criteria of the new view and use it in you grid.


    Regards Faisal

    Monday, February 18, 2013 2:11 PM
  • Hi,

    Enable trace and see more details about the error:

    http://exploringxrm.wordpress.com/2012/01/12/enabling-trace-in-microsoft-dynamics-crm-2011/

    You have define which columns you want return (like faisal write), if you want all attributes you need use the node i said.

    Hope this helps.


    Pedro Azevedo Crm Specialist 4.0\2011

    Monday, February 18, 2013 2:13 PM
  • I managed to use Faisal code aftyer you (Azevedo)pointed me to the trace log files

    thank you both.

    i would have one more question please. How can I now filter these activities based on a lookup('regardingobjectid') field on the form

    Thanks

    Monday, February 18, 2013 5:39 PM
  • Hi,

    Like that:

    <condition attribute="regardingobjectid" operator="eq" value='"+ Xrm.Page.data.entity.getId() + "' />

    One tip for generate FetchXml is doing what faisal refer, make a AdvancedFind a you can download de FetchXML, helps a lot.

    PS: Set faisal or my post or both as answer and\or useful.

    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful.

    Pedro Azevedo Crm Specialist 4.0\2011


    • Proposed as answer by Azevedo PedroMVP Monday, February 18, 2013 5:47 PM
    • Edited by Azevedo PedroMVP Monday, February 18, 2013 5:49 PM
    • Marked as answer by _cram Monday, February 18, 2013 7:45 PM
    Monday, February 18, 2013 5:47 PM
  • Thanks a lot for the help
    Monday, February 18, 2013 7:46 PM
  • <HTML><HEAD>
    <SCRIPT type=text/javascript>
    function getUrlVars() {
               // Read a page's GET URL variables and return them as an associative array.
                  var vars = [],
                     hash;
                  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                  for (var i = 0; i < hashes.length; i++) {
                      hash = hashes[i].split('=');
                      vars.push(hash[0]);
                      vars[hash[0]] = hash[1];
                  }
                  return vars;
              }
     
        function getFetchXML() {
                 parameters = getUrlVars(); //which leads to:
              var contactId= parameters['ID'];
          var strXML = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true"><entity name="activitypointer"><attribute name="subject"/><attribute name="activityid"/><attribute name="scheduledstart"/><attribute name="regardingobjectid"/><attribute name="prioritycode"/><attribute name="scheduledend"/><attribute name="activitytypecode"/><order attribute="scheduledend" descending="false"/><link-entity name="activityparty" from="activityid" to="activityid" alias="aa"><filter type="and"><condition attribute="partyid" operator="eq" uitype="contact" value="'+contactId+'"/></filter></link-entity></entity></fetch>';
             
    //alert(strXML);
            return strXML;
        }
    </SCRIPT>
    <META content=NO-CACHE http-equiv=CACHE-CONTROL>
    <META charset=utf-8></HEAD>
    <body onload="document.getElementById('fetchinput').value = getFetchXML();resultRender.submit();">
            <form id="resultRender" action="/AdvancedFind/fetchData.aspx" method="post">
            <input type="hidden" name="FetchXml" id="fetchinput" value='' />
            <input value='<grid name="resultset" object="4200" jump="subject" select="1" icon="1" preview="1"><row name="result" id="activityid" multiobjectidfield="activitytypecode"><cell name="activitytypecode" width="100" /><cell name="subject" width="300" /><cell name="regardingobjectid" width="100" /><cell name="prioritycode" width="100" /><cell name="scheduledstart" width="140" /><cell name="scheduledend" width="140" /><cell name="instancetypecode" width="100" ishidden="1" /></row></grid>'type="hidden" name="LayoutXml" /> 
            <input name="EntityName" type="hidden" value="activitypointer"/>
            <input name="DefaultAdvFindViewId" type="hidden" value="{00000000-0000-0000-00AA-000010001899}"/>
            <input name="ViewId" type="hidden" value="{00000000-0000-0000-00AA-000010001899}"/>
            <input name="ViewType" type="hidden" value="1039"/>
            <input name="SortCol" type="hidden" value="scheduledend:1;"/>
            <input name="UIProvider" type="hidden"/>
            <input name="DataProvider" type="hidden"/>
            </form>
        </body>
    </html>

    You can make parameterised dynamic iframes

    Regards Faisal

    Tuesday, February 19, 2013 12:13 PM