We all know that Fetch XML is the wonderful and great feature given in CRM.
Today, I got an error while working on retrieving some records from CRM. The issue was caused by the special characters.
Here is the my C# code in which I am retrieving account information by passing name.
{
Entity entAccount = null;
string strAccountName = “johnson & johnson”;
string strFetchXML = @”
<condition attribute='name' operator='eq' value='" + strAccountName + “‘/>” +
@”
“;
EntityCollection entCollection = objService.RetrieveMultiple(new FetchExpression(strFetchXML));
if (entCollection != null && entCollection.Entities.Count > 0)
{
entAccount = entCollection.Entities[0];
}
return entAccount;
}
And after I execute, got the below exception.
Don’t worry, this is very simple to solve. Just use HTMLEncode before passing the dynamic values.
Here is the thing what I have changed for making the code to work.
Hope it helps.
—
Happy CRM’ing
Gopinath.
Thanks, this is useful!
LikeLike