簡體   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