简体   繁体   English

CRM Dynamics获取相关帐户的联系人

[英]CRM Dynamics Get contacts of a related Account

I am creating phone call activities against accounts in CRM, I need to assign the to property of the phone call to the retrieved accounts related contact, how can I do this, please see my code below 我正在针对CRM中的帐户创建电话活动,我需要将电话的to属性分配给检索到的帐户相关联系人,我该如何做,请参见下面的代码

public static void GetRelevantOutboundCallCenter(IOrganizationService service)
    {
        QueryExpression qe = new QueryExpression();
        qe.EntityName = "account";
        qe.ColumnSet = new ColumnSet("new_accountactionedstatus", "name", "telephone1", "primarycontactid");
        qe.Criteria.AddCondition("new_deliverystatus", ConditionOperator.Equal, 279640000);
        qe.Criteria.AddCondition("new_province", ConditionOperator.Equal, 100000018);
        qe.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);


        EntityCollection response = service.RetrieveMultiple(qe);

        var counter = 0;

        foreach (Entity account in response.Entities)
        {
            PhoneCall phone = new PhoneCall();

            ActivityParty from = new ActivityParty();
            phone.OwnerId = from.PartyId = new EntityReference("systemuser", new Guid("6DEFA813-56F9-E411-80CC-00155D0B0C2D"));

            ActivityParty to = new ActivityParty();
            to.PartyId = account.ToEntityReference();

            phone.From = new ActivityParty[] { from };
            phone.DirectionCode = true;
            phone.To = new ActivityParty[] { to };// I need to set the related Contact of the account here
            phone.PhoneNumber = account.Attributes["telephone1"].ToString();
            phone.Subject = "TEST FOR OUTBOUND";
            service.Create(phone);

            counter++;

            if (counter == 438)
                return;
        }
    }

This is where I set the lookup account, I need this to be the contact related to the retrieved account -- phone.To = new ActivityParty[] { to }; 这是我设置查找帐户的地方,我需要它是与检索到的帐户相关的联系人-phone.To = new ActivityParty [] {to};

In case you want to assign your calls to primary contact of account change line 如果您想将呼叫分配给帐户更改专线的主要联系人

to.PartyId = account.ToEntityReference();

to line 到线

to.PartyId = account.GetEntityAttribute<EntityReference>("primarycontactid");

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

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