locked
MS CRM 4: Problem with like operator and "%"! RRS feed

  • Question

  • Hi,

    I wrote a piece of code in OnLoad section for Quote main form for fetching the filtered price lists.

    Everything works like a charm but when I put '%' in condition area, the price list lookup form can not be loaded and I get an error! (In fact I want to filter price lists with the last characters on their names...)

    Mentioned code and trace lines in bellow:

    var CurrentUserBDCode = GetCurrentUserBDCode();
    if (CurrentUserBDCode!=null)
    {
    	CurrentUserBDCode = "%" + CurrentUserBDCode ; 
    	var fetchStr = "<fetch mapping='logical'>" +
    			"  <entity name='pricelevel'>" +
    			"    <all-attributes />" +
    			"    <filter>" +
    			"      <condition attribute='name' operator='like' value='%" + CurrentUserBDCode + "' />" +
    			"    </filter>" +
    			"  </entity>" +
    			"</fetch> ";
    	crmForm.all.pricelevelid.lookupbrowse = 1; 
    	crmForm.all.pricelevelid.AddParam("search", fetchStr);
    }
    

    Error: Exception of type 'System.Web.HttpUnhandledException' was thrown.

    Error Message: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Error Details: Exception of type 'System.Web.HttpUnhandledException' was thrown.

    Source File: Not available

    Line Number: Not available

    Request URL: http://**************/_controls/lookup/lookupsingle.aspx?class=PriceLevelByCurrency&objecttypes=1022&browse=1&search=<fetch mapping='logical'>  <entity name='pricelevel'>    <all-attributes />    <filter%253

    Stack Trace Info: [XmlException: The '%' character, hexadecimal value 0x25, cannot be included in a name. Line 1, position 87.]
       at ...

    Please help me to find the cause and solution...

    Sunday, August 5, 2012 5:27 AM

Answers

  • Finally I found the root of this problem!

    The "CurrentUserBDCode" variable contains number and it seems that after merging with '%", the result will interpreted as something like hexadecimal value!!!

    Changing the comparison method solved my problem... 

    • Marked as answer by Soroosh81 Monday, August 6, 2012 4:33 AM
    Monday, August 6, 2012 4:33 AM

All replies

  • Hi Soroosh81.

    You actually have 2 '%'. One in the variable and one in the FetchXML-definition.

    Try removing the one in the FetchXML.


    Best Regards Kenn

    Sunday, August 5, 2012 7:53 PM
  • Thanks for your reply.

    I removed it.

    var CurrentUserBDCode = GetCurrentUserBDCode();
    if (CurrentUserBDCode!=null)
    {
    	CurrentUserBDCode = "%" + CurrentUserBDCode ; 
    	var fetchStr = "<fetch mapping='logical'>" +
    			"  <entity name='pricelevel'>" +
    			"    <all-attributes />" +
    			"    <filter>" +
    			"      <condition attribute='name' operator='like' value='" + CurrentUserBDCode + "' />" +
    			"    </filter>" +
    			"  </entity>" +
    			"</fetch> ";
    	crmForm.all.pricelevelid.lookupbrowse = 1; 
    	crmForm.all.pricelevelid.AddParam("search", fetchStr);
    }

    But the problem exists yet and I get the same error...

    Monday, August 6, 2012 4:04 AM
  • Finally I found the root of this problem!

    The "CurrentUserBDCode" variable contains number and it seems that after merging with '%", the result will interpreted as something like hexadecimal value!!!

    Changing the comparison method solved my problem... 

    • Marked as answer by Soroosh81 Monday, August 6, 2012 4:33 AM
    Monday, August 6, 2012 4:33 AM