如何在 MS Dynamics CRM 中创建操作和呼叫操作?
How to create Action and Call action in MS Dynamics CRM?
如何在 MS Dynamics CRM 中逐步创建操作和调用操作?
在 MS Dynamics CRM 中调用操作的方法有多少?
行动代替Workflow/plugin有什么好处?
操作数
操作是 Microsoft Dynamics 365 中的一种流程。您可以直接从工作流或对话框中调用操作,包括自定义操作,而无需编写代码!详细信息:从工作流或对话框调用自定义操作
也可以通过使用 Microsoft Dynamics 365 Web 服务的 运行 自定义代码调用操作。
您可以调用操作:
它可以从客户端和服务器端调用,启用单点方法(实施一次,随处使用),例如:- 从在 plug-in 中执行的代码,自定义工作流和任何C# 代码。
从放置在应用程序中并使用 JavaScript 代码执行操作的命令。
可以直接接收输入参数和 return 输出参数,类似于组织级 Web 服务
来自与使用 Microsoft Dynamics 365 Web 服务的另一个系统的集成。
来自使用 Microsoft Dynamics 365 Web 服务的自定义客户端应用程序。
为什么要使用动作?
操作为编写业务逻辑打开了一系列可能性。在 Actions 之前,实现业务流程的主要方式仅限于 plug-ins 或自定义工作流活动。通过操作,您可以执行创建、更新、删除、分配或执行操作等操作。在内部,操作会创建自定义 Dynamics 365 消息。借助 Actions,您可以创建自定义消息(例如:submitquote、leadtoax 等。定义并激活操作后,开发人员可以像使用 Microsoft Dynamics 365 平台提供的任何其他消息一样使用该消息。
假设您在报价单上有一个按钮,可以将信息从 CRM 发送到另一个平台(例如,另一个平台是 AX)。
创建并激活自定义操作(设置 > 流程)
现在您可以在某些事件(OnLoad、OnSave 等)中从 JavaScript 调用此 Action(ofs_submitquotetoax)。在此示例中,我从报价单上的提交报价按钮调用操作,该操作将报价信息发送到其他系统 (AX)。
// Call this below method from Button click event or from any event on the form
// For Alert.showLoding method you can see another Alert.js library
// For Process.callAction method you can see another Process.js library
// You can download Alert.js & Process.js from this Path: https://drive.google.com/drive/folders/0B2CUbevE8v9YMkZlMEhUZ3NJc1U
function submitquote() {
var actionName = "ofs_submitquoteax";
var entityName = Xrm.Page.data.entity.getEntityName();
var entityId = Xrm.Page.data.entity.getId();
Alert.showLoading("Submitting...", 400, 150);
var inputParams = [
{
key: "EntityRef", type: Process.Type.EntityReference,
value: new Process.EntityReference(entityName, entityId)
}
];
// call process callection method
Process.callAction(actionName, inputParams, cloneSuccessCallback, errorCallback);
}
function cloneSuccessCallback() {
Alert.hide();
Alert.show("Action Success", "", null, "SUCCESS");
Alert.hide();
var entityName = Xrm.Page.data.entity.getEntityName();
var entityId = Xrm.Page.data.entity.getId();
Xrm.Utility.openEntityForm(entityName, entityId);
//Xrm.Page.data.refresh();
}
function errorCallback(error, trace) {
alert(error);
alert(alert(error));
}
e,对于此事件,您可以注册并触发插件并接收 input-parameter(在我们的例子中,我们发送 input-parameter 键作为 EntityRef,我们在其中发送 entityName 和 entityId。
参数:操作唯一名称、输入参数(数组)、成功回调(函数)、错误回调(函数)、CRM Base URL(forms/views 不需要)
每个输入参数对象都应包含键、值和类型。类型由 Process.Type 枚举定义。 EntityReference 值应该是包含 id 和 entityType 的对象。
Success Callback 函数应该接受一个参数,它是一组输出参数,每个参数包含键和值。
您可以通过以下方式编写插件并访问输入参数
protected override void ExecuteCrmPlugin(LocalPluginContext localContext)
{ // Register the plugin in PreValidation stage as this plugin will trigger from Javascript (Action)
if (localContext == null)
{
throw new InvalidPluginExecutionException("localContext");
}
IPluginExecutionContext context = localContext.PluginExecutionContext;
if (context.Depth > 1) { return; }
IOrganizationService service = localContext.OrganizationService;
ITracingService trace = localContext.TracingService;
Entity quoteEntity = null;
EntityReference qEntity = null;
if (context.InputParameters.Contains("EntityRef") && context.InputParameters["EntityRef"] is EntityReference)
{
//if (context.PrimaryEntityName.ToLower() != "quote") { return; }
qEntity = context.InputParameters["EntityRef"] as EntityReference;
if (qEntity.LogicalName.ToLower().Equals("quote"))
{
try
{
quoteEntity = service.Retrieve("quote", qEntity.Id, new ColumnSet("ofs_parentaccountid", "quotenumber", "revisionnumber", "ofs_well"));
// Execute Your logic
}
catch (Exception ex)
{
trace.Trace(string.Format("Exception Quote_Create_AXIntegration Plugin: {0}", new[] { ex.ToString() }));
}
}
}
else { return; }
}
注册你的插件,然后按照下面的方式注册步骤,你可以在下面看到你的自定义消息名称 screen-shot "ofs_submitquoteax";
如何在 MS Dynamics CRM 中逐步创建操作和调用操作? 在 MS Dynamics CRM 中调用操作的方法有多少? 行动代替Workflow/plugin有什么好处?
操作数
操作是 Microsoft Dynamics 365 中的一种流程。您可以直接从工作流或对话框中调用操作,包括自定义操作,而无需编写代码!详细信息:从工作流或对话框调用自定义操作
也可以通过使用 Microsoft Dynamics 365 Web 服务的 运行 自定义代码调用操作。
您可以调用操作:
它可以从客户端和服务器端调用,启用单点方法(实施一次,随处使用),例如:- 从在 plug-in 中执行的代码,自定义工作流和任何C# 代码。 从放置在应用程序中并使用 JavaScript 代码执行操作的命令。 可以直接接收输入参数和 return 输出参数,类似于组织级 Web 服务 来自与使用 Microsoft Dynamics 365 Web 服务的另一个系统的集成。 来自使用 Microsoft Dynamics 365 Web 服务的自定义客户端应用程序。
为什么要使用动作?
操作为编写业务逻辑打开了一系列可能性。在 Actions 之前,实现业务流程的主要方式仅限于 plug-ins 或自定义工作流活动。通过操作,您可以执行创建、更新、删除、分配或执行操作等操作。在内部,操作会创建自定义 Dynamics 365 消息。借助 Actions,您可以创建自定义消息(例如:submitquote、leadtoax 等。定义并激活操作后,开发人员可以像使用 Microsoft Dynamics 365 平台提供的任何其他消息一样使用该消息。
假设您在报价单上有一个按钮,可以将信息从 CRM 发送到另一个平台(例如,另一个平台是 AX)。
创建并激活自定义操作(设置 > 流程)
现在您可以在某些事件(OnLoad、OnSave 等)中从 JavaScript 调用此 Action(ofs_submitquotetoax)。在此示例中,我从报价单上的提交报价按钮调用操作,该操作将报价信息发送到其他系统 (AX)。
// Call this below method from Button click event or from any event on the form
// For Alert.showLoding method you can see another Alert.js library
// For Process.callAction method you can see another Process.js library
// You can download Alert.js & Process.js from this Path: https://drive.google.com/drive/folders/0B2CUbevE8v9YMkZlMEhUZ3NJc1U
function submitquote() {
var actionName = "ofs_submitquoteax";
var entityName = Xrm.Page.data.entity.getEntityName();
var entityId = Xrm.Page.data.entity.getId();
Alert.showLoading("Submitting...", 400, 150);
var inputParams = [
{
key: "EntityRef", type: Process.Type.EntityReference,
value: new Process.EntityReference(entityName, entityId)
}
];
// call process callection method
Process.callAction(actionName, inputParams, cloneSuccessCallback, errorCallback);
}
function cloneSuccessCallback() {
Alert.hide();
Alert.show("Action Success", "", null, "SUCCESS");
Alert.hide();
var entityName = Xrm.Page.data.entity.getEntityName();
var entityId = Xrm.Page.data.entity.getId();
Xrm.Utility.openEntityForm(entityName, entityId);
//Xrm.Page.data.refresh();
}
function errorCallback(error, trace) {
alert(error);
alert(alert(error));
}
e,对于此事件,您可以注册并触发插件并接收 input-parameter(在我们的例子中,我们发送 input-parameter 键作为 EntityRef,我们在其中发送 entityName 和 entityId。
参数:操作唯一名称、输入参数(数组)、成功回调(函数)、错误回调(函数)、CRM Base URL(forms/views 不需要)
每个输入参数对象都应包含键、值和类型。类型由 Process.Type 枚举定义。 EntityReference 值应该是包含 id 和 entityType 的对象。
Success Callback 函数应该接受一个参数,它是一组输出参数,每个参数包含键和值。
您可以通过以下方式编写插件并访问输入参数
protected override void ExecuteCrmPlugin(LocalPluginContext localContext)
{ // Register the plugin in PreValidation stage as this plugin will trigger from Javascript (Action)
if (localContext == null)
{
throw new InvalidPluginExecutionException("localContext");
}
IPluginExecutionContext context = localContext.PluginExecutionContext;
if (context.Depth > 1) { return; }
IOrganizationService service = localContext.OrganizationService;
ITracingService trace = localContext.TracingService;
Entity quoteEntity = null;
EntityReference qEntity = null;
if (context.InputParameters.Contains("EntityRef") && context.InputParameters["EntityRef"] is EntityReference)
{
//if (context.PrimaryEntityName.ToLower() != "quote") { return; }
qEntity = context.InputParameters["EntityRef"] as EntityReference;
if (qEntity.LogicalName.ToLower().Equals("quote"))
{
try
{
quoteEntity = service.Retrieve("quote", qEntity.Id, new ColumnSet("ofs_parentaccountid", "quotenumber", "revisionnumber", "ofs_well"));
// Execute Your logic
}
catch (Exception ex)
{
trace.Trace(string.Format("Exception Quote_Create_AXIntegration Plugin: {0}", new[] { ex.ToString() }));
}
}
}
else { return; }
}
注册你的插件,然后按照下面的方式注册步骤,你可以在下面看到你的自定义消息名称 screen-shot "ofs_submitquoteax";