【问题标题】:CRM 2011 update incident when email arrives电子邮件到达时的 CRM 2011 更新事件
【发布时间】:2013-05-13 22:03:35
【问题描述】:

在 CRM 中,当电子邮件到达并包含跟踪令牌时,它们会自动将相关字段设置为事件(或与事件相关的任何内容)

不幸的是,记录墙没有更新此信息,因此即使您正在关注此案例,也不会提醒您注意新活动。

我想在电子邮件或事件(或两者)上编写一个插件,以更新记录墙并创建一个任务以在 3 天内跟进该电子邮件。

我正在查看 SDK,但当电子邮件到达 CRM 时/已设置相关字段时,我看不出管道中的适当事件是什么。

文档中没有很好地描述 CRM 电子邮件创建生命周期。 [握拳]

困扰我的其他事情

我似乎无法包含获取强类型电子邮件、帖子或案例的参考(让我抓狂)

测试这个真的很难(比应该的更难)

编辑这是我当前的代码

namespace Assembly.Plugins
{
using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

/// <summary>
/// PostEmailDeliverIncoming Plugin.
/// </summary>    
public class PostEmailDeliverIncoming : Plugin
{
    /// <summary>
    /// Initializes a new instance of the <see cref="PostEmailDeliverIncoming"/> class.
    /// </summary>
    public PostEmailDeliverIncoming()
        : base(typeof(PostEmailDeliverIncoming))
    {
        RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "DeliverIncoming", "email", ExecutePostEmailDeliverIncoming));

        // Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
        // You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
    }


    protected void ExecutePostEmailDeliverIncoming(LocalPluginContext localContext)
    {
        if (localContext == null)
        {
            throw new ArgumentNullException("localContext");
        }

        //Extract the tracing service for use in debugging sandboxed plug-ins.
        ITracingService tracingService = localContext.TracingService;

        // Obtain the execution context from the service provider.
        IPluginExecutionContext context = localContext.PluginExecutionContext;

        // Obtain the organization service reference.
        var service = localContext.OrganizationService;

             // The InputParameters collection contains all the data passed in the message request.
        if (!context.InputParameters.Contains("Target") || !(context.InputParameters["Target"] is Entity)) 
            return;

        // Obtain the target entity from the input parmameters.
        var target = (Entity)context.InputParameters["Target"];

        // Verify that the target entity represents an account.
        // If not, this plug-in was not registered correctly.
        if (target.LogicalName != "email")
            return;

        if((string)target["direction"] != "Incoming")
            return;

        if (target["regardingobjectid"] == null)
            return;

        try
        {
            // if its not a case I don't care
            var incident = service.Retrieve("incident", (Guid)target["regardingobjectid"], new ColumnSet(true));
            if (incident == null) 
                return;

            var post = new Entity("post");

            post["regardingobjectid"] = target["regardingobjectid"];

            post["source"]=new OptionSetValue(0);
            post["text"] = String.Format("a new email has arrived.");

            // Create the task in Microsoft Dynamics CRM.
            tracingService.Trace("FollowupPlugin: Creating the post.");
            service.Create(post);


            // Create a task activity to follow up with the account customer in 7 days. 
            var followup = new Entity("task");

            followup["subject"] = "Follow up incoming email.";
            followup["description"] = "An email arrived that was assigned to a case please follow it up.";
            followup["scheduledstart"] = DateTime.Now.AddDays(3);
            followup["scheduledend"] = DateTime.Now.AddDays(3);
            followup["category"] = context.PrimaryEntityName;

            // Refer to the email in the task activity.
            if (context.OutputParameters.Contains("id"))
            {
                var regardingobjectid = new Guid(context.OutputParameters["id"].ToString());
                followup["regardingobjectid"] = new EntityReference("email", regardingobjectid);
            }

            // Create the task in Microsoft Dynamics CRM.
            tracingService.Trace("FollowupPlugin: Creating the task activity.");
            service.Create(followup);
        }
        catch (FaultException<OrganizationServiceFault> ex)
        {
            throw new InvalidPluginExecutionException("An error occurred in the FollupupPlugin plug-in.", ex);
        }
        catch (Exception ex)
        {
            tracingService.Trace("FollowupPlugin: {0}", ex.ToString());
            throw;
        }
    }
}
}

【问题讨论】:

    标签: c# plugins dynamics-crm-2011


    【解决方案1】:

    我一直在与这个完全相同的问题作斗争,并遇到了这篇文章。我想我会为您(如果您仍然需要它)以及将来遇到此问题的任何其他人发布解决方案。

    这是我得出的解决方案: - 使用插件注册工具在适当的步骤注册一个新图像(Stage = "40", MessageName = "DeliverIncoming") - 将新图像设置为发布图像 - 在您的插件中获取 Post Image 的实体 ID:

    Guid emailID = context.PostEntityImages["PostImage"].Id;
    Entity emailFromRetrieve = localContext.OrganizationService.Retrieve(
        "email",
        emailID,
        new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
    Email email = emailFromRetrieve.ToEntity<Email>();
    
    if (email.RegardingObjectId == null)
    {
        return;
    }
    
    var regardingObject = email.RegardingObjectId;
    

    希望这会有所帮助!

    【讨论】:

    【解决方案2】:

    我现在实际上正在开发一个非常相似的插件。我会在发送到某个电子邮件地址的电子邮件到达时创建一个自定义实体。它还通过“相关”字段将传入电子邮件与该新记录相关联。我在 Create of Email 上添加了 Pre-Operation 步骤,效果很好,包括来自路由器的传入电子邮件。

    我不确定 CRM 何时填写“相关”字段。您可能会查看 Post-Operation 并查看它是否设置在那里?

    关于相关字段的一个有趣警告(哈哈!):与单个查找字段不同,相关对象的名称实际上存储在 ActivityPointer 表中,因此当您更新相关字段时,请务必在 EntityReference 上设置名称。如果你不这样做,关于查找仍然会有一个可点击的图标,但不会有任何文本。我是这样做的:

            email.RegardingObjectId = [yourentity].ToEntityReference();
            email.RegardingObjectId.Name = email.Subject;
    

    希望有帮助!

    【讨论】:

    • 我会确保添加这个,你如何测试?目前我正在部署并希望......这真的很可怕。
    • 是的,部署和祈祷! :) 除了直接在 CRM 服务器上调试之外,我还使用了另一种调试方法:stackoverflow.com/questions/8401537/…
    • 我是 CRM 2013 开发的新手。您声明“我的电子邮件在发送到某个电子邮件地址的电子邮件到达时创建一个自定义实体”我希望在电子邮件到达特定队列时触发一个插件。那会和你的一样吗?创建电子邮件?
    【解决方案3】:

    我最终在电子邮件实体的工作流程中执行此操作

    步骤

    1. 创建新的工作流程,我称之为“接收电子邮件工作流程”
    2. 范围即组织
    3. 选择电子邮件作为实体并检查“记录字段更改”
    4. 添加一个检查关于(案例)的步骤:案例包含数据

    如果为真:

    1. 添加创建帖子的步骤
    2. 编辑帖子中的属性

      • 文本:此案例有来自 {From(E-mail)} 的 {Direction(E-mail)} 电子邮件活动
      • 来源:自动发布
      • 关于:{关于(电子邮件)}
    3. 添加创建任务的步骤

    4. 编辑任务中的属性
      • 主题:跟进{主题(电子邮件)}
      • 关于:{关于(电子邮件)}

    【讨论】:

      【解决方案4】:

      尝试使用以下代码:

      if ((bool)entity["directioncode"] == false)
      

      代替你的代码:

      if((string)target["direction"] != "Incoming")
      

      【讨论】:

      • 这个问题已经有一个公认的答案。如果您正在寻找未解决的问题,可以在这里找到它们:stackoverflow.com/unanswered
      猜你喜欢
      • 2012-10-10
      • 2013-07-23
      • 1970-01-01
      • 1970-01-01
      • 2015-01-22
      • 1970-01-01
      • 1970-01-01
      • 2012-11-13
      • 2012-05-21
      相关资源
      最近更新 更多