locked
Using LOOP in fetchxml RRS feed

  • Question

  • Hi, I deeply need your help. I've try to use an array in a condition part, but it doesn't work. Here is my code:

      var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                      "<entity name='new_pledge'>" +
                        "<attribute name='new_name' />" +
                        "<attribute name='new_pledgeid' />" +
                        "<attribute name='new_marketvalue' />" +
                        "<order attribute='new_name' descending='false' />" +
                        "<filter type='or'>" +
    
                       "<condition attribute='new_pledgeid' operator='eq' value='" 
    
            for (var i = 0; i < gravid.length; i++) {
    
                + gravid[i] + "' />" ;
            }
        +
            "</filter>" +
          "</entity>" +
        "</fetch>";
    
    
            var layoutXml = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
                      "<row name='result' id='new_pledgeid'>" +
                        "<cell name='new_name' width='300' />" +


    • Edited by gMary Saturday, February 28, 2015 4:35 PM
    Saturday, February 28, 2015 4:34 PM

Answers

  • Try below code

    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                     "<entity name='new_pledge'>" +
                       "<attribute name='new_name' />" +
                       "<attribute name='new_pledgeid' />" +
                       "<attribute name='new_marketvalue' />" +
                       "<order attribute='new_name' descending='false' />" +
                       "<filter type='or'>" +
                            "<condition attribute='new_pledgeid' operator='in' >";
    for (var i = 0; i < gravid.length; i++)
    {
        fetchXml += "<value>{" + gravid[i] + "}</value>";// if you having {} with guid in gravid, then please remove the hardcoded "{}" from for loop
    }
    
    fetchXml += "           </condition>" +
                        "</filter>" +
                    "</entity>" +
                  "</fetch>";

    • Proposed as answer by Piyush Parate Saturday, February 28, 2015 5:08 PM
    • Marked as answer by gMary Saturday, February 28, 2015 5:35 PM
    Saturday, February 28, 2015 5:07 PM

All replies

  • Try below code

    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                     "<entity name='new_pledge'>" +
                       "<attribute name='new_name' />" +
                       "<attribute name='new_pledgeid' />" +
                       "<attribute name='new_marketvalue' />" +
                       "<order attribute='new_name' descending='false' />" +
                       "<filter type='or'>" +
                            "<condition attribute='new_pledgeid' operator='in' >";
    for (var i = 0; i < gravid.length; i++)
    {
        fetchXml += "<value>{" + gravid[i] + "}</value>";// if you having {} with guid in gravid, then please remove the hardcoded "{}" from for loop
    }
    
    fetchXml += "           </condition>" +
                        "</filter>" +
                    "</entity>" +
                  "</fetch>";

    • Proposed as answer by Piyush Parate Saturday, February 28, 2015 5:08 PM
    • Marked as answer by gMary Saturday, February 28, 2015 5:35 PM
    Saturday, February 28, 2015 5:07 PM
  • Thank you so much, it works.
    Saturday, February 28, 2015 5:35 PM