locked
operator="in" , Fetch Xml, MS CRM 2011 RRS feed

  • Question

  • hi,

    i have a guid's string array.

    ex: string[] recordGuids;

    i want to use this in fetchxml by using condition operator "in".

    i have tried this below code but no success ("The remote server returned an error: NotFound.").

                var fetchXml = @"<fetch mapping='logical'>
                                   <entity name='annotation'>
                                      <attribute name='filename' />
                                      <filter>
                                         <condition attribute='objectid' operator='in'>"+
                                            "<value>" + recordGuids + "</value>" + 
                                         "</condition>"+
                                    "</filter>"+
                                   "</entity>"+
                                "</fetch>";

    when i debug and check the query, that was something like this( which is wrong query ).

    <fetch mapping='logical'> <entity name='annotation'> <attribute name='filename' /> <filter> <condition attribute='objectid' operator='in'>

    <value>System.String[]</value>

    </condition>

    </filter>

    </entity>

    </fetch>


    can anyone give me an idea to retrieve set of records by using condition operator "in" by passing string array.


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    • Edited by Ravitheja J Thursday, January 24, 2013 10:23 AM
    Thursday, January 24, 2013 10:18 AM

Answers

  • You will have to run a loop that will go until the recordGuids length, something similar to below

    for(var i = 1; i<= recordGuids.length;i++)
    {
    fetchXml += "<value>" + recordGuids[i] + "</value>"
    }

    Try building the string incorporating the above logic for inserting values.

    Hope this will help you!


    Piyush

    • Proposed as answer by san Sanz Thursday, January 24, 2013 11:02 AM
    • Marked as answer by Ravitheja J Thursday, January 24, 2013 11:22 AM
    Thursday, January 24, 2013 10:28 AM

All replies

  • You will have to run a loop that will go until the recordGuids length, something similar to below

    for(var i = 1; i<= recordGuids.length;i++)
    {
    fetchXml += "<value>" + recordGuids[i] + "</value>"
    }

    Try building the string incorporating the above logic for inserting values.

    Hope this will help you!


    Piyush

    • Proposed as answer by san Sanz Thursday, January 24, 2013 11:02 AM
    • Marked as answer by Ravitheja J Thursday, January 24, 2013 11:22 AM
    Thursday, January 24, 2013 10:28 AM
  • hi Piyush,

    thanks for the reply.

    looping is my last option. any other way ?


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, January 24, 2013 10:56 AM
  • I see that's the only way out to your problem. Is there any limitation on using it in your scenario? I would personally recommend this.

    If this helps, then don't forget to mark is as answer.


    Piyush

    Thursday, January 24, 2013 10:59 AM
  • hi if your recordGuids are a List,

    you can write in a single line,

    recordGuids.Select(a=> "<value>" +a.ToString() + "</value>");



    By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".


    • Edited by san Sanz Thursday, January 24, 2013 11:05 AM
    Thursday, January 24, 2013 11:04 AM
  • Hi I need your help. I also tried to loop in my fetchxml , but it doesn't work. Please help me.

      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 <= Pledgeid.length; i++)
                {
                       Pledgeid[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' />" +
                        "<cell name='new_pledgeid' width='100' />" +
                        "<cell name='new_marketvalue' width='100' />" +
                       // "<cell name='new_by_months' width='100' />" +
                      "</row>" +
                    "</grid>";

    Saturday, February 28, 2015 4:08 PM
  • hi Can you please 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='eq' value='";
    				   
    				
    				   
           for(var i = 1; i<= Pledgeid.length;i++)
    {
    fetchXml += "<value>" + Pledgeid[i] + "</value>";
    }
        
          
                    fetchXml +=   "' />"+
                       
                        "</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' />" +
                        "<cell name='new_pledgeid' width='100' />" +
                        "<cell name='new_marketvalue' width='100' />" +
                       // "<cell name='new_by_months' width='100' />" +
                      "</row>" +
                    "</grid>";


    By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".

    Sunday, March 1, 2015 1:07 PM