Wednesday, May 21, 2014

Read all Notes having attachment related to case entity in MS CRM 2011 and MS CRM 2013

Here is the sample code.

public static EntityCollection GetAllNotes(Guid CaseId, IOrganizationService service)
{
EntityCollection results = null;
try
{

QueryExpression Query = new QueryExpression
{
EntityName = "annotation",
ColumnSet = new ColumnSet("filename""documentbody""filesize""mimetype","isdocument"),
Criteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,

Conditions =
{
new ConditionExpression
{
AttributeName = "objectid",
Operator = ConditionOperator.Equal,
Values = { CaseId }
},
new ConditionExpression
{
AttributeName = "isdocument",
Operator = ConditionOperator.Equal,
Values = { true }
},
}
}
};

results = service.RetrieveMultiple(Query);

}
catch (Exception Ex)
{
Console.Write(Ex.Message);
if (Ex.InnerException != null)
{
Console.WriteLine(Ex.InnerException.Message);
Console.ReadLine();
}
}
return results;

}

No comments:

Loading...