我有一个自定义工作流程事件,它可以通过我的自定义工作流程事件创建新机会。 我将该事件作为行动步骤。我正在使用 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);
这是调用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/