【问题标题】:put the contact list of account to the cc field in email将帐户的联系人列表放入电子邮件中的 cc 字段
【发布时间】:2011-10-04 12:19:34
【问题描述】:

我有一个任务是在 crm 4 中制作一个插件,它应该 1. 在电子邮件的主题字段中输入帐户名称,然后 2. 将帐户的联系人列表放入电子邮件的 cc 字段. 我做的第一件事,它的工作,但第二...不是那么多... 我看过一些样本,但没有一个能阻止我…… 我想获得帮助并解释如何找到属于该帐户的联系人列表,然后将列表放入 cc 字段。 这是开始...:

namespace mail
{
public class Class1 : IPlugin
{
        public void Execute(IPluginExecutionContext context)
        {
            DynamicEntity entity = null;

            if (context.InputParameters.Properties.Contains("Target") &&
               context.InputParameters.Properties["Target"] is DynamicEntity)
            {
                entity = (DynamicEntity)context.InputParameters.Properties["Target"];

                if (entity.Name != EntityName.account.ToString())
                {
                    return;
                }
            }
            else
            {
                return;
            }

            try
            {
                // updating the subject of the email
                ICrmService service = context.CreateCrmService(true);
                account accountRecord = (account)service.Retrieve("account", ((Key)entity.Properties["accountid"]).Value, new ColumnSet(new string[] { "name" }));
                String str = String.Empty;
                str = accountRecord.name.ToString();
                DynamicEntity followup = new DynamicEntity();
                followup.Name = EntityName.email.ToString();

                followup.Properties = new PropertyCollection();
                followup.Properties.Add(new StringProperty("subject", str));

                //updating the CC of the email

                TargetCreateDynamic targetCreate = new TargetCreateDynamic();
                targetCreate.Entity = followup;

                CreateRequest create = new CreateRequest();
                create.Target = targetCreate;

                CreateResponse created = (CreateResponse)service.Execute(create);
            }
            catch
            {
                throw new InvalidPluginExecutionException(
                      "An error occurred in the AccountUpdateHandler plug-in.");
            }
        }
    }
}

【问题讨论】:

    标签: email plugins dynamics-crm-4


    【解决方案1】:

    你可以试试这样的,

    List<BusinessEntity> contactList = GetNeededContacts(crmService, sourceEntity);
    email targetEmail = GetTargetEmail(crmService, emailid);            
    foreach (DynamicEntity contact in contactList)
                {
                    activityparty contActParty = new activityparty() { partyid = new Lookup("contact", contact.contactid.Value };
                    List<activityparty> tmpList = targetEmail.cc.ToList();
                    tmpList.Add(contActParty);
                    targetEmail.cc = tmpList.ToArray();
                }
    crmService.Update(targetEmail);
    

    您只需开发获取联系人、用户或帐户引用的功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 2016-10-20
      • 1970-01-01
      • 2013-08-26
      • 1970-01-01
      • 2019-05-24
      • 2019-06-03
      相关资源
      最近更新 更多