日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【转】Dynamics CRM 365零基础入门学习(三)Dynamics 通过Web API 来调用自定义的Action(使用插件)

發布時間:2023/12/10 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【转】Dynamics CRM 365零基础入门学习(三)Dynamics 通过Web API 来调用自定义的Action(使用插件) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天想實現一個Search Product的功能,首先要將數據展示在頁面,然后前端根據查詢需求進行處理。之前是在salesforce中實現的,可以定義一個Search Product的頁面,然后在頁面中訪問查詢數據的Webservice即可。但是在Dynamic 365中并沒有這種直接調用的方式,最終找到一種方式就是,前端頁面通過Js調用工作流中的Action,而在Action上綁定了插件。


實現效果

(1) 實現html頁面并導入系統

在設置中找到自定義項,然后進去自定義系統,選擇Web資源,然后將之前做好的頁面上傳到系統。

(2) 自定義Action

首先新建一個action,實體設置上可以設置為全局的,也可以單獨設定某個實體。

注意:

注冊該action,方法同插件注冊,在注冊step時message選擇我們的action的唯一名稱,很多人在這一步的message里不顯示action的名字,確保兩點:第一你的action激活了,第二你的插件注冊器是在你激活action后再打開的。

設置好action,這邊設置了兩個輸入參數和一個輸出參數,設置完后保存并且激活。

(3) 開發Plugin項目

這里我們簡單介紹一下插件的基本用法
1. 要繼承IPlugin,并實現Excute方法。
2. 從Service provider里獲取執行上下文
3. 我們可以檢查出發插件的實體名稱
4. 還可以檢查觸發的事件,是creat, update還是delete
5. 輸入參數里獲取觸發的實體
6. 通過service factory獲取IOrganizationService,當CreateOrganizationService方法的參數為null時,表示的是系統用戶,當參數為context.UserId 或Guid.Empty時,表示的是當前用戶
7. 最后是DoAction方法,插件的邏輯就可以在這里實現了。
以下是實現插件的代碼:

public void Execute(IServiceProvider serviceProvider){IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);//傳入兩個參數String InParameters1 = context.InputParameters["InParameters1"] as String;String InParameters2 = context.InputParameters["InParameters2"] as String;//查詢//EntityReference entityRef = context.InputParameters["Target"] as EntityReference;string fetchProductXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='new_be_eligible_pn__c'><attribute name='new_be_eligible_pn__cid' /><attribute name='new_name' /><attribute name='createdon' /><attribute name='new_value_category__c' /><attribute name='new_is_tp_part__c' /><attribute name='new_country__c' /><attribute name='new_available_quantity_flag__c' /><order attribute='new_name' descending='false' /><filter type='and'><condition attribute='new_country__c' operator='eq' value='Italy' /></filter><link-entity name='new_product' from='new_productid' to='new_product__c' link-type='inner' alias='a_e79f28ae2899e811a96f000d3a828e6c'><attribute name='new_wifi__c' /><attribute name='new_warranty__c' /><attribute name='new_type__c' /><attribute name='new_sub_series__c' /><attribute name='new_series__c' /><attribute name='new_screen_size__c' /><attribute name='new_name' /><attribute name='new_product_hierarchy__c' /><attribute name='new_description' /><attribute name='new_productcode' /><attribute name='new_os__c' /><attribute name='new_memory__c' /><attribute name='new_hdd__c' /><attribute name='new_cpu__c' /><attribute name='new_brand__c' /><attribute name='new_battery__c' /><filter type='and'><filter type='or'><condition attribute='new_type__c' operator='like' value='%PC System Unit%' /><condition attribute='new_type__c' operator='eq' value='Non System Unit' /></filter></filter></link-entity><link-entity name='new_product_sales_country__c' from='new_product_sales_country__cid' to='new_psc__c' link-type='inner' alias='a_c278acd92899e811a96f000d3a828e6c'><attribute name='new_currencyisocode' /><attribute name='new_channel_price__c' /><filter type='and'><condition attribute='new_sales_status__c' operator='like' value='%12%' /></filter></link-entity></entity></fetch>";EntityCollection products = service.RetrieveMultiple(new FetchExpression(fetchProductXml));//傳出參數context.OutputParameters["OutParameters"] = products;//遍歷productsforeach (var pair in products.Entities){foreach (var pa in pair.Attributes){Console.WriteLine(pa.Key + ": " + pa.Value);}}Console.WriteLine(products);}

(4)數據查詢方式,本篇使用FetchXML

在以上的代碼實現中,我使用了FetchXML的方式實現,對于多條件跨表查詢,返回多條記錄很方便。常用的結構如下,
SDK中有很多類似的案例。

其中XML這塊我們可以使用高級查詢來自動生成

最后我們可以導出XML文件

(5)Js調用自定義的Action

最后可以看到輸出結果:

總結:

在on-premises的開發中我們往往把復雜的業務處理邏輯封裝成接口供前端js調用,但在online的開發中這樣的開發方式無疑增加了成本(需另外架設服務器,添置域名,配置https協議證書等),通過web api調用action給我們提供了新的可行的方式。實現了需求。在下一章我們將分享如何調試插件。

總結

以上是生活随笔為你收集整理的【转】Dynamics CRM 365零基础入门学习(三)Dynamics 通过Web API 来调用自定义的Action(使用插件)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。