首页 > 其他分享 >Dynamic CRM调用WCF接口获取选项集的说明数据

Dynamic CRM调用WCF接口获取选项集的说明数据

时间:2023-09-15 15:12:43浏览次数:39  
标签:foton string Dynamic entity ex WCF action new CRM

一、SQL语句:

  select Value Id,Label Name 

  from LocalizedLabel a left join AttributePicklistValue b on a.ObjectId=b.AttributePicklistValueId

  left join OptionSet c on b.OptionSetId=c.OptionSetId

  where a.ComponentState=0 and b.ComponentState=0 and c.ComponentState=0

  and c.Name='{name}' and a.LanguageId=2052

  and a.ObjectColumnName='{desc}' order by Value asc

  参数说明:name 为选项集名称。desc为字段名称:Description,选项集说明;DisplayName,选项集标签

 

二、后端WCF接口封装获取选项集说明数据的方法

    /// <summary>
    /// 获取选项集说明数据
    /// </summary>
    /// <param name="name">选项集的名称</param>
    /// <returns></returns>     //[WebGet(RequestFormat = WebMessageFormat.Json)]
    public static string GetOptionSetList(string name,string desc)
    {
      KDOperateResult response = new KDOperateResult();       var list = new List<OptionSet>();
      try
      {
        if (!string.IsNullOrWhiteSpace(name))
          list = SQLDBHELPER.ExecSQL<OptionSet>($"select Value Id,Label Name from LocalizedLabel a left join AttributePicklistValue b on                                                                                                                          a.ObjectId=b.AttributePicklistValueId left join OptionSet c on b.OptionSetId=c.OptionSetId where                                                                                                                                 a.ComponentState=0 and b.ComponentState=0 and c.ComponentState=0 and c.Name='{name}' and                                                                                                                         a.LanguageId=2052 and a.ObjectColumnName='{desc}' order by Value asc");
        response.code = "0";
        response.message = new JavaScriptSerializer().Serialize(list);
      }
      catch (Exception ex)
      {
        LoggerHelper.Instance.Error("UploadAttachmentKD索赔获取选项集索赔明细附件说明出错:", ex);
        response.code = "2";
        response.message = ex.Message.ToString();
      }

      return new JavaScriptSerializer().Serialize(response);
    }   三、调用WCF接口的三种方式   1.在浏览器地址输入已GET方式调用,参数在地址栏通过?选项集名称&desc方式连接     WCF地址/rest/GetOptionSetList?name=选项集名称&desc=Description      说明:使用该方式需要在方法上面打赏WebGet标签:[WebGet(RequestFormat = WebMessageFormat.Json)]     2.通过POST方式调用

      var entity = {};
      entity.foton_action = "GetOptionSetList";
      entity.foton_actionparams = JSON.stringify({
        name: 选项集名称,
        desc: Description
      })

 

      $.ajax({
        url: "WCF地址/OTDDMSService.svc/rest/" + entity.foton_action,
        type: "POST",
        data: entity.foton_actionparams,
        contentType: "application/json;charset=utf-8",
        async: entity.async == undefined ? true : entity.async,
        success: function (data) {
        },
        error: function (xhr, textStatus, errorThrown) {
        }
      })

 

  3.通过触发插件的方式,在插件后端调用

   说明:需新建一实体,调用时向实体插入数据,并触发该实体的create插件,在插件中调用WCF接口实现

      var entity = {};
      entity.foton_action = "GetOptionSetList";
      entity.foton_actionparams = JSON.stringify({
        name: 选项集名称,
        desc: Description
      })

      $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: Xrm.Page.context.getClientUrl() + "/api/data/v8.2/foton_pluginactions",
        data: JSON.stringify(entity),
        beforeSend: function (XMLHttpRequest) {
          XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
          XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
          XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        async: entity.async == undefined ? true : entity.async,
        //success: function (data) {
          // if (cbfun != undefined)
          // cbfun(data);
        //},
        error: function (xhr) {
          if (cbfun != undefined) {
            var pData = JSON.parse(JSON.parse(xhr.responseText.toString()).error.message);
            cbfun(pData);
          }
        }
      });

 

   后端插件代码实现如下:   

    public class PluginAction : IPlugin
    {
      public void Execute(IServiceProvider serviceProvider)
      {
        IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
        IOrganizationService service = serviceFactory.CreateOrganizationService(null);

        try
        {
          string result = "";

          Entity target = (Entity)context.InputParameters["Target"];
          string environment = target.GetAttributeValue<string>("foton_environment");
          string action = target.GetAttributeValue<string>("foton_action");
          string actionParams = target.GetAttributeValue<string>("foton_actionparams");

          result = post(environment, action, actionParams);

          StringBuilder strPluginTrace = new StringBuilder();
          strPluginTrace.Append("【environment】" + environment + "。");
          strPluginTrace.Append("【action】" + action + "。");
          strPluginTrace.Append("【actionParams】" + actionParams + "。");
          strPluginTrace.Append("【result】" + result + "。");

          PluginTrace.info(strPluginTrace.ToString());

          throw new InvalidPluginExecutionException("error:" + result);
        }
        catch (Exception ex)
        {
          OperateResultByPlugin operateResultByPlugin = null;

          if (ex.Message.IndexOf("_red_fox_error") == 0)
          {
            OperateResultByInterface operateResultByInterface = JsonConvert.DeserializeObject<OperateResultByInterface>(ex.Message.Substring(14));
            operateResultByPlugin = JsonConvert.DeserializeObject<OperateResultByPlugin>(operateResultByInterface.d);
          }
          else
          {
            operateResultByPlugin = new OperateResultByPlugin();
            operateResultByPlugin.code = "-2";
            operateResultByPlugin.message = ex.Message;

            PluginTrace.error(ex.Message);
          }

          throw new InvalidPluginExecutionException(JsonConvert.SerializeObject(operateResultByPlugin));
        }
      }


      #region 发送api请求,返回api处理结果
      private string post(string environment, string action, string actionparams)
      {
        try
        {
          string url_prefix = ""WCF地址/rest/"";
          string url_postfix = action;
          string url_params = actionparams;

 

          byte[] byteArray = Encoding.UTF8.GetBytes(url_params);

          HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url_prefix + url_postfix));
          webRequest.Proxy = null;
          webRequest.Timeout = 300000;
          webRequest.Method = "POST";
          webRequest.ContentType = "application/json;charset=utf-8";
          webRequest.ContentLength = byteArray.Length;
          Stream stream = webRequest.GetRequestStream();
          stream.Write(byteArray, 0, byteArray.Length);
          stream.Close();

          HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
          StreamReader sr = new StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("utf-8"));

          return sr.ReadToEnd();
        }
        catch (Exception ex)
        {
          throw new InvalidPluginExecutionException("请求接口失败:" + ex.ToString());
        }
      }
      #endregion


      #region 结果模型
      private class OperateResultByInterface
      {
        public string d { get; set; }
      }


      private class OperateResultByPlugin
      {
        public string code { get; set; }
        public string message { get; set; }
        public string extra { get; set; }
      }
      #endregion
    }

标签:foton,string,Dynamic,entity,ex,WCF,action,new,CRM
From: https://www.cnblogs.com/jiangyuhu/p/17705051.html

相关文章

  • PPT| 企业CRM系统建设项目蓝图汇报方案 P25
    本人在咨询机构从事咨询工作多年,二十年一线数字化规划咨询经验,提供制造业数智化转型规划服务,顶层规划/企业架构/数据治理/数据安全解决方案资料干货.【智能制造数字化咨询】该PPT共25页,如需完整原版 方案,点击右上角红色按钮关注+私信。......
  • Dynamic CRM 注册插件
    注册插件:  1.启动插件注册工具  2.创建一个新的链接              3.输入登录信息,然后点击登陆注意:红框中标识的第一个是链接方式,第二个是IP地址,第三个是端口号,第四个是......
  • 关于 SAP CRM User Status 处理的示例 ABAP 代码
    源代码如下:*&---------------------------------------------------------------------**&ReportZSTATUS_INITIAL_LOAD*&---------------------------------------------------------------------**&*&----------------------------------------------......
  • 根据指定关键字搜索指定时间范围内的 SAP CRM 中间件 BDOC 的 ABAP 小工具分享
    工具源代码如下:REPORTzscan_bdoc_via_keyword.PARAMETERS:startTYPEsmw3_bdoc-snd_dateOBLIGATORYDEFAULTsy-datlo,endTYPEsmw3_bdoc-snd_dateOBLIGATORYDEFAULTsy-datlo,keywordTYPEstringLOWERCASEOBLIGATORYDEFAULT'CR......
  • [LeetCode] 85. Maximal Rectangle_Hard tag: Dynamic Programming
    Givena rowsxcols binary matrix filledwith 0'sand 1's,findthelargestrectanglecontainingonly 1'sandreturn itsarea. Example1:Input:matrix=[["1","0","1","0","0"],["1&q......
  • 微服务启动失败,报错信息:java.lang.RuntimeException: dynamic-datasource Please chec
    【问题描述】Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'dataSource'definedinclasspathresource[com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DynamicDataSourceAutoConfiguration.cl......
  • 一个实际例子演示动态时间规整(Dynamic Time Warping, DTW )算法
    用一个实际例子,演示动态时间规整(DynamicTimeWarping,DTW )算法  动态时间规整(DynamicTimeWarping,DTW)是一种用于度量两个时间序列之间的差异的算法,尤其是当这两个序列出现时间偏移或速度不同的情况。例如,DTW可用于语音识别或股价数据分析。以下是一个简单的DTW算......
  • 用友U8 CRM客户关系管理系统 getemaildata.php 任意文件读取漏洞&任意文件上传漏洞
    漏洞简介用友U8CRM客户关系管理系统getemaildata.php存在任意文件读取漏洞,攻击者通过漏洞可以获取到服务器中的敏感文件。用友U8CRM客户关系管理系统getemaildata.php文件存在任意文件上传漏洞,攻击者通过漏洞可以获取到服务器权限,攻击服务器漏洞影响用友U8CRM客户关系......
  • crm--纯后端部署
    博客地址:https://www.cnblogs.com/zylyehuo/技术栈:supervisor+nginx+uwsgi+django+virtualenv+mariadb基本流程crm纯后端部署是通过模板语言进行和前端通信的,前端代码写在后端中<!--模板语言-->{{static.el}}配置后端,uwsgi+crm进行项目运行环境变量......
  • 简读||Dynamic Metasurface Antennas for Uplink Massive MIMO Systems
    用于上行链路大规模MIMO系统的动态超表面天线摘要:大规模多输入多输出(MIMO)通信是近年来人们广泛关注的焦点。虽然大规模MIMO的理论增益已经确立,但在实践中实现具有大规模天线阵列的MIMO系统仍具有挑战性。与大规模MIMO系统相关的实际挑战包括成本、功耗和物理尺寸的增加。......