将帐户的联系人列表放入电子邮件的抄送字段

发布于 2024-12-08 04:47:15 字数 2116 浏览 3 评论 0原文

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

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.");
            }
        }
    }
}

i have a mission to make a plug-in in crm 4 which should 1. put in the subject field of an email the name of the account and then 2. put the contact list of account to the cc field of the email.
the first thing i did and it work, but the second... not so much...
i have seen some samples but none of them was close to halp me...
i would like to have help and explain of how to find the list of the contact that belong to the account and then put the list in the cc field.
here is the begining...:

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.");
            }
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风月客 2024-12-15 04:47:15

您可以尝试这样的方法,

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);

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

You can try something like this,

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);

You only have to develop the function to get the contact, user or account references.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文