locked
get distinct accounts with attached docs RRS feed

  • Question

  • I am having trouble making a query getting all the accounts with attached doc.  my problem is if the account has multiple docs it returns the account more than once.

    how do i get distinct account with attached docs

    below is code to get attached docs

     //link to doc
                        LinkEntity OnlyAttachments = new LinkEntity();
                        OnlyAttachments.LinkFromEntityName = EntityNameString;
                        OnlyAttachments.LinkFromAttributeName = EntityIDString;
    
                        OnlyAttachments.LinkToEntityName = EntityName.annotation.ToString();
                        OnlyAttachments.LinkToAttributeName = "objectid";
    
                        ConditionExpression ce = new ConditionExpression();
                        ce.AttributeName = "isdocument";
                        ce.Operator = ConditionOperator.Equal;
                        ce.Values = new object[] { "1" };
    
                        FilterExpression filterPrincipalOnlyAttachments = new FilterExpression();
                        filterPrincipalOnlyAttachments.FilterOperator = LogicalOperator.And;
                        filterPrincipalOnlyAttachments.Conditions = new ConditionExpression[] { ce };
    
                        OnlyAttachments.LinkCriteria = filterPrincipalOnlyAttachments;
    
                        QueryExpression query = new QueryExpression();
                        query.ColumnSet = new AllColumns();
                        query.EntityName = EntityName.account.ToString();
                        query.LinkEntities = new LinkEntity[] { OnlyAttachments };
                       
                        RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
                        retrieve.Query = query;
    
                        RetrieveMultipleResponse response = (RetrieveMultipleResponse)crmService.Execute(retrieve);
    Tuesday, January 12, 2010 6:23 PM

Answers

All replies