简体   繁体   English

如何在MS Dynamics CRM中获取帐户的所有联系人并建立电子邮件列表?

[英]How to get all contacts of an Account and build an email List in MS Dynamics CRM?

I've an account Id, and would like to get the collection of contacts under the account to build an email list. 我有一个帐户ID,并希望获得该帐户下的联系人集合以建立电子邮件列表。


    //build up Email
    private Email BuildEmail(ActivityParty allcontacts){.... build my emailhere}

    private List<Entity> GetAllContactsFromAccountId(Guid accountId, List<Entity> toList)
    {          

        //how can I get all the contacts here
        foreach (Entity contact in Account.Contact.Entities)//????
        {
            Entity activityParty = new Entity("activityparty");
            activityParty["partyid"] = new EntityReference("??", e.Id);

            if (toList.Any(t => t.GetAttributeValue<EntityReference>("partyid").Id == e.Id)) continue;

            toList.Add(activityParty);
        }

        return toList;
    }

You can find the Account key "parentcustomerid" in contact entity. 您可以在联系人实体中找到客户键“ parentcustomerid”。 you can get contact collection by account id as below. 您可以按以下帐户ID获取联系人集合。

  private EntityCollection getContactByAccountId(IOrganizationService service, Guid accountId)
    {
        QueryExpression query = new QueryExpression("contact");
        query.ColumnSet = new ColumnSet(new string[] { "contactid", "fullname" });
        query.Criteria.AddCondition(new ConditionExpression("parentcustomerid", ConditionOperator.Equal, accountId))
        return service.RetrieveMultiple(query);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM