locked
Flush FetchXML result RRS feed

  • Question

  • I have couple of pick list which are used to set condition in my Fetch XML. My issue is that when I chose a value from the pick list, I get the desired result. When I close the lookup windows and remove my filter and click again on lookup button that is when I get to see the old result, instead of a result without any filter applied. 

    I like to know if there is any way I can flush the old search result from the lookup.

    Thank you

    Syed

     

    Thursday, May 27, 2010 12:07 PM

Answers

  • Hi Syed, 

    Sorry for the late response. Too busy recently. 

    When conditionfound equals to 0, you need to reset search parameter. So the last few lines of code should look like this: 

    if (conditionfound == '1')
    {
      field.AddParam("search", fetchstring);
    }
    else
    {
      field.AddParam("search", "");
    }


    Daniel Cai | http://danielcai.blogspot.com
    • Marked as answer by SyedPro Wednesday, June 2, 2010 10:43 AM
    Tuesday, June 1, 2010 6:28 PM

All replies

  • Could you just describe the context? Custom web app? winform? etc.
    My blog : http://mscrmtools.blogspot.com

    All my tools on my new dedicated site: MSCRMTools Repository
    Thursday, May 27, 2010 12:32 PM
    Moderator
  • I have the pick list and the lookup button on the proposal form. I hope this clarifies the context. 
    Thursday, May 27, 2010 1:54 PM
  • It will help if you can post some of your code here. 
    Daniel Cai | http://danielcai.blogspot.com
    Thursday, May 27, 2010 5:19 PM
  • Sorry about not posting the code, should have thought of it earlier.Here the is code, it has multiple if conditions.

     

    var field = crmForm.all.new_entityid;

    if(crmForm.ObjectId == null) 

        // Disable lookup for new account record as there can be no contacts 

        field.Disabled = true; 

    field.lookupbrowse = 1; 

    var conditionfound = '0';

    var fetchstring = "<fetch mapping='logical'><entity name='new_entity'>" ;

    fetchstring = fetchstring + "<filter type='and'>";

    if (crmForm.all.new_units.DataValue != null && crmForm.all.new_units.DataValue != '')

    {

        conditionfound = '1';

        fetchstring = fetchstring + "<condition attribute='new_noofunit' operator='eq' value='" +  crmForm.all.new_units.DataValue + "' />" ;

    }

    // *********Some more if conditions are here

     

    if (crmForm.all.new_location.DataValue != null && crmForm.all.new_location.DataValue != '')

    {

        conditionfound = '1';

        fetchstring = fetchstring + "<condition attribute='new_location' operator='eq' value='" +  crmForm.all.new_location.DataValue + "' />" ;

    }

    fetchstring = fetchstring +  "</filter></entity></fetch>"; 

    if (conditionfound =='1')

    {

        field.AddParam("search", fetchstring);

    }

     

     

    *********************

    Here is my issue. I have attached the above fetchxml() method with a lookup. when I do a search with unit value (e.g = 1) selected it gives me my result that includes unit value equals to 1 but when I re-run the search without either unit or location value entered, I get the same output as in the case of last preselected unit value instead of all the data output without any condition, the result one should get with a lookup where no fetchXml is used.

    Thank you in advance.

     

    Syed

     

     

     

    Monday, May 31, 2010 6:41 AM
  • Hi Syed, 

    Sorry for the late response. Too busy recently. 

    When conditionfound equals to 0, you need to reset search parameter. So the last few lines of code should look like this: 

    if (conditionfound == '1')
    {
      field.AddParam("search", fetchstring);
    }
    else
    {
      field.AddParam("search", "");
    }


    Daniel Cai | http://danielcai.blogspot.com
    • Marked as answer by SyedPro Wednesday, June 2, 2010 10:43 AM
    Tuesday, June 1, 2010 6:28 PM
  • "Sorry for the late response. Too busy recently."

    No need to apologize, I do very well understand, thank you for your response. Now the script is working properly.

    Thank you

    Syed

    Wednesday, June 2, 2010 10:42 AM