Attachment File Data Truncated with QueryExpression.Distinct

Today, I am experiencing one strange issue regarding with the attachment file from CRM being corrupted upon downloading through the external web site.
That external web site is consuming the interface web service layer that CRM team implemented to perform CRUD and other specific data transactions.
But the problem is that the attachment files bigger than 2KB are always corrupted downloaded through that site.
Upon tracing the issue, I just found out that when Distinct property of the QueryExpression  is set to true, the "documentbody"  column in the "annotation" entity of the result set is truncated at the 2000 characters.

 string entityName = "annotation";  
 Guid recordId = new Guid("00000000-0000-0000-0000-000000000000"); // one of the notes' GUID  
 string field = "documentbody";  
 QueryExpression query = new QueryExpression(entityName);  
 query.Criteria.AddCondition(new ConditionExpression(entityName + "id", ConditionOperator.Equal, recordId));  
 query.ColumnSet = new ColumnSet(field);  
 query.Distinct = true;  
 EntityCollection result = service.RetrieveMultiple(query);  

I’m not sure what’s the root cause of the issue but it only happens at the "documentbody"  column in the "annotation" entity but not for any other single line or multiline attribute of any other entity.
But since Distinct property should not be there in the first place in that generic method (just copy+paste of code from somewhere else), I just remove it from the QueryExpression  and it is working fine afterwards.

Comments

Popular Posts