zoukankan      html  css  js  c++  java
  • Dynamics CRM 2015/2016 Web API:Unbound Custom Action 和 Bound Custom Action

    今天我们再来看看Bound/Unbound Custom Action吧,什么是Custom Action?不知道的小伙伴们就out了,Dynamics CRM 2013就有了这个功能啦。和WhoAmI这类消息一样,我们都能够通过代码去调用它们。仅仅只是呢,今天我要给大家讲讲怎么用Web API的方式去调用它们。

    Custom Action也被划分为Bound和Unbound两种类型了,它们的详细含义和之前讲的Function和Action没有差别。唯一的差别就是,这里的Custom Action是我们自己配置的,这里科普下。我们能够在Setting-》Process里面创建Action,它的创建界面例如以下:

    Bound Custom Action


    Unbound Custom Action


    他们的调用方式和OOB Action是一样的,没有差别,详细能够參考以下的代码片段:

    Bound Custom Action

     HttpRequestMessage custBoundActionReq = new HttpRequestMessage(HttpMethod.Post, webApiUrl + "/accounts(723ef58a-75bb-e511-80d9-c4346bc43f3c)/Microsoft.Dynamics.CRM.new_CreatePrimaryContactForAccount");
                custBoundActionReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", auth.AcquireToken().AccessToken);
    
                JObject custBoundActionContent = new JObject();
                custBoundActionContent.Add("FirstName", "Jeff");
                custBoundActionContent.Add("LastName", "Xiong");
                //custBoundActionContent.Add("Telephone", "15000303158");
                //custBoundActionContent.Add("Email", "jeff.xiong@ghostbear.com");
    
                custBoundActionReq.Content = new StringContent(JsonConvert.SerializeObject(custBoundActionContent), Encoding.UTF8, "application/json");
    
                HttpResponseMessage custBoundActionResp = await client.SendAsync(custBoundActionReq);
    
                if (custBoundActionResp.IsSuccessStatusCode)
                {
                    JObject result = JsonConvert.DeserializeObject<JObject>(await custBoundActionResp.Content.ReadAsStringAsync());
                    Console.WriteLine(result);
                }

    Unbound Custom Action

                HttpRequestMessage custActionReq = new HttpRequestMessage(HttpMethod.Post, webApiUrl + "/new_CreateDemoAccount_UA");///"accounts(723ef58a-75bb-e511-80d9-c4346bc43f3c)/Microsoft.Dynamics.CRM.new_CreateDemoAccount"
                custActionReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", auth.AcquireToken().AccessToken);
    
                JObject custActionContent = new JObject();
                custActionContent.Add("AccountName", "Jeff's Demo Account");
                custActionReq.Content = new StringContent(JsonConvert.SerializeObject(custActionContent), Encoding.UTF8, "application/json");
    
                HttpResponseMessage custActionResp = await client.SendAsync(custActionReq);
    
                if (custActionResp.IsSuccessStatusCode)
                {
                    JObject result = JsonConvert.DeserializeObject<JObject>(await custActionResp.Content.ReadAsStringAsync());
                    Console.WriteLine(result);
    
                }

    是不是非常轻松呢?小伙伴们要知道。在之前,我们定义这种Custom Action得花九牛二虎之力去呀。倒腾 web service什么的。

    如今我们仅仅须要通过UI界面就能够轻松的配置一个不错的Action,是不是非常幸福呢。



  • 相关阅读:
    2020.08.28【周报】
    区间合并【排序、栈】
    1042 数字0-9的数量【解题数分DP】
    asp.net数据分页方法
    纯css面板插件,自适应,多样式
    c#winform图表控件使用示例
    使用妹子UI开发的体验分享
    阿里云储存代码整理(由三卷天书整理)
    测试程序的时候用到写参数或者错误日志的几个方法,用来方便发现错误
    fineUI表格控件各属性说明
  • 原文地址:https://www.cnblogs.com/jhcelue/p/6994571.html
Copyright © 2011-2022 走看看