繁体   English   中英

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

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

如何在MS Dynamics CRM中逐步创建操作和调用操作? MS Dynamics CRM中有多少种调用操作的方法? 用动作代替工作流/插件有什么好处?

操作

动作是Microsoft Dynamics 365中的一种过程。您可以直接从工作流或对话框中调用动作,包括自定义动作,而无需编写代码! 详细信息:从工作流或对话框中调用自定义操作

也可以通过运行使用Microsoft Dynamics 365 Web服务的自定义代码来调用操作。

您可以调用动作:

可以从客户端和服务器端调用它,从而实现单点访问(一次实施,可以在任何地方使用),例如:-从在插件,自定义工作流程中执行的代码以及任何C#代码中实现。 从放置在应用程序中的命令开始,并使用JavaScript代码执行操作。 可以以直接方式接收输入参数并返回输出参数,类似于组织级别的Web服务通过与使用Microsoft Dynamics 365 Web服务的另一个系统的集成来进行。 从使用Microsoft Dynamics 365 Web服务的自定义客户端应用程序中。

为什么要使用动作?

动作为组合业务逻辑提供了多种可能性。 在执行Actions之前,实现业务流程的主要方式仅限于插件或自定义工作流活动。 使用动作,您可以执行操作,例如创建,更新,删除,分配或执行动作。 在内部,操作会创建自定义Dynamics 365消息。 使用动作,您可以创建自定义消息(例如: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,对于此事件,您可以注册并触发插件并接收输入参数(在本例中,我们将输入参数键作为EntityRef发送,在其中发送entityName和entityId。

参数:操作唯一名称,输入参数(数组),成功回调(函数),错误回调(函数),CRM基本URL(在表单/视图上不是必需的)

每个输入参数对象都应包含键,值和类型。 类型由Process.Type枚举定义。 EntityReference值应为包含id和EntityType的对象。

成功回调函数应接受一个参数,该参数是一组输出参数,每个参数包含键和值。

您可以通过以下方式编写插件并访问输入参数

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

    }

注册您的插件,然后按以下方式注册步骤,您可以在以下屏幕截图“ ofs_submitquoteax”中注意到您的自定义消息名称;

在此处输入图片说明

参考: 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