简体   繁体   English

如何在MS Dynamics CRM中创建操作和呼叫操作?

[英]How to create Action and Call action in MS Dynamics CRM?

How to create Action step by step and Call action in MS Dynamics CRM? 如何在MS Dynamics CRM中逐步创建操作和调用操作? How many ways to call action in MS Dynamics CRM? MS Dynamics CRM中有多少种调用操作的方法? What the benefits of action instead of Workflow/plugin? 用动作代替工作流/插件有什么好处?

Actions 操作

Actions are a type of process in Microsoft Dynamics 365. You can invoke actions, including custom actions, directly from a workflow or dialog, without writing code! 动作是Microsoft Dynamics 365中的一种过程。您可以直接从工作流或对话框中调用动作,包括自定义动作,而无需编写代码! More information: Invoke custom actions from a workflow or dialog 详细信息:从工作流或对话框中调用自定义操作

Actions can also be invoked by running custom code that uses the Microsoft Dynamics 365 Web services. 也可以通过运行使用Microsoft Dynamics 365 Web服务的自定义代码来调用操作。

You can call actions: 您可以调用动作:

It can be called from both client & server side, enabling the Single Point of Approach (Implement once, consume anywhere), for ex:- From code that executes within a plug-in, custom workflow and any C# code. 可以从客户端和服务器端调用它,从而实现单点访问(一次实施,可以在任何地方使用),例如:-从在插件,自定义工作流程中执行的代码以及任何C#代码中实现。 From a command that is placed in the application and executes the operation using JavaScript code. 从放置在应用程序中的命令开始,并使用JavaScript代码执行操作。 Can receive input parameters and return output parameters in a straight forward manner, similar to an Organization level Web Service From an integration with another system that uses the Microsoft Dynamics 365 web services. 可以以直接方式接收输入参数并返回输出参数,类似于组织级别的Web服务通过与使用Microsoft Dynamics 365 Web服务的另一个系统的集成来进行。 From a custom client application that uses the Microsoft Dynamics 365 web services. 从使用Microsoft Dynamics 365 Web服务的自定义客户端应用程序中。

Why use actions? 为什么要使用动作?

Actions open a range of possibilities for composing business logic. 动作为组合业务逻辑提供了多种可能性。 Before Actions, the primary way to implement business processes was limited to plug-ins or custom workflow activities. 在执行Actions之前,实现业务流程的主要方式仅限于插件或自定义工作流活动。 With Actions, you can perform operations, such as Create, Update, Delete, Assign, or Perform Action. 使用动作,您可以执行操作,例如创建,更新,删除,分配或执行动作。 Internally, an action creates a custom Dynamics 365 message. 在内部,操作会创建自定义Dynamics 365消息。 With Actions you can create a custom message (for example: submitquote , leadtoax etc. Once an action is defined and activated, a developer can use that message like any of the other messages provided by the Microsoft Dynamics 365 platform. 使用动作,您可以创建自定义消息(例如:submitquote,leadtoax等。定义并激活动作后,开发人员可以像使用Microsoft Dynamics 365平台提供的其他任何消息一样使用该消息。

Suppose you have button on Quote form which sends information from CRM to another platform (for ex another platform is AX). 假设您在“报价”表单上具有按钮,该按钮会将信息从CRM发送到另一个平台(例如另一个平台是AX)。

Create and activate a Custom Action (Settings > Process) 创建并激活自定义操作(设置>流程)

在此处输入图片说明

Now you can call this Action(ofs_submitquotetoax) from JavaScript on some event (OnLoad, OnSave,etc). 现在,您可以在某些事件(OnLoad,OnSave等)上从JavaScript调用此Action(ofs_submitquotetoax)。 In this example I am calling the action from SUBMIT QUOTE button on Quote form which sending quote information to other system (AX). 在此示例中,我要从“报价”表单上的“提交报价”按钮调用操作,该操作会将报价信息发送到其他系统(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, for this event you can register & trigger a Plugin and receive the input-parameter (in our case we sending input-parameter key as EntityRef in which we are sending entityName and entityId. e,对于此事件,您可以注册并触发插件并接收输入参数(在本例中,我们将输入参数键作为EntityRef发送,在其中发送entityName和entityId。

Parameters: Action Unique Name, Input Parameters (array), Success Callback (function), Error Callback (function), CRM Base URL (not required on forms/views) 参数:操作唯一名称,输入参数(数组),成功回调(函数),错误回调(函数),CRM基本URL(在表单/视图上不是必需的)

Each Input Parameter object should contain key, value, and type. 每个输入参数对象都应包含键,值和类型。 Types are defined by the Process.Type enum. 类型由Process.Type枚举定义。 EntityReference values should be an object containing id and entityType. EntityReference值应为包含id和EntityType的对象。

The Success Callback function should accept one argument which is an array of output parameters, each containing key, and value. 成功回调函数应接受一个参数,该参数是一组输出参数,每个参数包含键和值。

You can write plugin in below way and access input parameter 您可以通过以下方式编写插件并访问输入参数

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

    }

Register your plugin and then register the step in below way, you can notice your custom message name in below screen-shot "ofs_submitquoteax"; 注册您的插件,然后按以下方式注册步骤,您可以在以下屏幕截图“ ofs_submitquoteax”中注意到您的自定义消息名称;

在此处输入图片说明

Ref: https://community.dynamics.com/crm/b/mylifemicrosoftdynamiccrm/archive/2017/04/17/microsoft-dynamics-crm-actions 参考: https : //community.dynamics.com/crm/b/mylifemicrosoftdynamiccrm/archive/2017/04/17/microsoft-dynamics-crm-actions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM