javascript - 使用 Notify.js 添加指向新创建的实体记录的链接 - CRM

标签 javascript c# dynamics-crm crm

我有一个自定义工作流程事件,它可以通过我的自定义工作流程事件创建新机会。 我将该事件作为行动步骤。我正在使用 Action ,因为它有输出。我需要获取我创建的机会的 ID。 我使用 Process.js 从 JS Web 资源调用该操作。之后,我使用 Notify.js 通知用户机会已创建。在该通知中,我需要有一个链接到新创建的机会的按钮。

以下是与输出参数相关的 C# 代码的一些部分。请注意,用于创造机会并执行更多任务的代码部分工作正常:

//define variable
[Output("Opportunity")]
[ReferenceTarget("opportunity")]
public OutArgument<EntityReference> NewOpportunity { get; set; }

//create opportunity and entity reference(i am not sure do ineed entity reference, or something else for that link)
Guid opportunityId = service.Create(opportunity);
EntityReference OppId = new EntityReference(opportunity.LogicalName, opportunityId);

//assign value to the output variable
NewOpportunity.Set(Econtext, OppId);

以下是我在操作定义中创建操作参数的方法: enter image description here

这是调用action的JS代码:

function toOpportunity(){

Process.callAction("ad_opportunity",
    [{
        key: "Target",
        type: Process.Type.EntityReference,
        value: { id: Xrm.Page.data.entity.getId(), entityType: "ad_productsamplerequest" }
    }],
    function (param) {
        //Success            
         Notify.add("New Opportunity was created:", "INFO", "opportunity",
    [{
        type: "button",
        text: "Go to opportunity",
        callback: function () {

        }
    }]);
    },
    function () {
        // Error
        alert("Opportunity was not created");
    }
);

只是说,它有效,行动被调用,机会被创造,之后有通知。只是不知道如何使用操作输出参数来设置机会的链接。

最佳答案

看起来您正在尝试处理 CodeActivity 类中的操作。这是行不通的。 OutArgument 属性只能在工作流程中访问,无法返回到调用进程。

相反,使用所需的输入和输出参数创建一个操作。然后创建一个插件并在此操作上注册同步更新后步骤。插件类实现必须将机会 ID 添加到 OutputParameters 集合中,如下所示:

public void Execute(IServiceProvider serviceProvider)
{
    var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    var service = factory.CreateOrganizationService(context.UserId);

    Entity opportunity;
    // TODO: add code here to build the opportunity.

    Guid opportunityId = service.Create(opportunity);
    context.OutputParameters.Add("NewOpportunity", new EntityReference("opportunity", opportunityId));
}

另请参阅 MSDN 上的说明.

关于javascript - 使用 Notify.js 添加指向新创建的实体记录的链接 - CRM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39946735/

相关文章:

javascript - WooCommerce - 从单独的 PHP 文件访问 'WC_Order'

javascript - 在 DDL 中查找 optgroup 的值

javascript - 我错过了什么? HTML > 主体 - 调整大小事件

workflow - 为什么使用插件注册工具注册自定义工作流程后需要重新启动 CRM 服务器才能正常工作

dynamics-crm - 仅当我在 Dynamics crm 中更新浏览器时,字段才会更新

javascript - 如何将加密与 FlexPaper 合并

C# AES 加密算法转Python3

c# - Wix - 如何在安装后从安装目录运行 exe 文件?

c# - 添加变量以跨解决方案访问

dynamics-crm - 访问云端 Microsoft Dynamics 365 数据的正确方法是什么? SDK 与 Web API