ThibC
ThibC

Reputation: 1

Filter lookup with fetchXML and special character '&' does not work

I am currently trying to filter a lookup field in Dynamics 365 CRM using a fetchXML in a javascript. I have to view all the products with a custom text field ('my_variantstatus') not equal to 'R&D Stage' (and some other values). I have a problem with the character "&".

Here is my filter xml: 

var filterXml = "<filter type='and'><condition attribute='my_variantstatus' operator='ne' value='R&amp;D stage'/><condition attribute='my_variantstatus' operator='ne' value='Discontinued'/></filter>";

I have already tried remplacing the ampersand '&' with : \&, &amp;, &#38;, encodeURIComponent('R&D stage'), %26 but none of them worked.

Please note that the script works well when I try to filter without the ampersand ('RD stage') and that it does not work with any other special character as well (quote, <, >, etc).

Upvotes: 0

Views: 762

Answers (1)

This is an usual problem, try the encoding to solve it.

var item = 'R&D stage';
var encodedItem = encodeURIComponent(item);

var filterXml = "<filter type='and'><condition attribute='my_variantstatus' operator='ne' value= '"+ encodedItem +"'/><condition attribute='my_variantstatus' operator='ne' value='Discontinued'/></filter>";

Upvotes: 0

Related Questions