【问题标题】:how to adapt old JS CRM 2011 to CRM 2015如何使旧的 JS CRM 2011 适应 CRM 2015
【发布时间】:2016-09-11 00:11:56
【问题描述】:

我是 Microsoft Dynamics CRM 的新手,我正在使用 CRM 2015。 我正在使用 CRM 2015,并且我被要求修复为 CRM 2011 开发的错误脚本。 它看起来像一个旧语法,我不知道如何将其调整为适用于 CRM 2015 的 JS。 该脚本管理用户角色和角色名称,我已通过 fetchXML 检索数据。

function onChangeValutator()
{  
     var idUser = Xrm.Page.getAttribute("erm_valutatorid").getValue()[0].id;

     // Use the Xrm.Page.context.getAuthenticationHeader() method 
     // available from the CRM form to generate the Soap header text.
     var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();

     // Define the SOAP XML to access Microsoft Dynamics CRM Web service.
     var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
     "<soap:Envelope xmlns:soap="+
     "\"http://schemas.xmlsoap.org/soap/envelope/\" "+
     "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
     "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 
     authenticationHeader+
     "<soap:Body>" + 
     // Specify the RetrieveMultiple message.
     "<RetrieveMultiple xmlns="+
     "\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
     // Specify that this is a QueryByAttribute query.
     "<query xmlns:q1="+
     "\"http://schemas.microsoft.com/crm/2006/Query\" "+
     "xsi:type=\"q1:QueryByAttribute\">" + 
     // Query the customeraddress entity.
     "<q1:EntityName>erm_source</q1:EntityName>" + 
     // Set the columns you want to return.
     "<q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
     "<q1:Attributes>" + 
     "<q1:Attribute>erm_roleid</q1:Attribute>" + 
     "</q1:Attributes>" + 
     "</q1:ColumnSet>" + 
     // Specify the attribute that you are querying on.
     "<q1:Attributes>" + 
     "<q1:Attribute>erm_sourceid</q1:Attribute>" + 
     "</q1:Attributes>" + 
     // Set the value of the attribute using the customerid 
     // value of the case record.
     "<q1:Values>" + 
     "<q1:Value xsi:type=\"xsd:string\">"+
     idUser+
     "</q1:Value>" + 
     "</q1:Values>" + 
     "</query>" + 
     "</RetrieveMultiple>" + 
     "</soap:Body>" + 
     "</soap:Envelope>";

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    var doc = xmlHttpRequest.responseXML;
    var source = doc.selectSingleNode("//BusinessEntity");

    var guidSource = source.childNodes[0];

    if (guidSource.text != null)
    {
        // Define the SOAP XML to access Microsoft Dynamics CRM Web service.
         xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
         "<soap:Envelope xmlns:soap="+
         "\"http://schemas.xmlsoap.org/soap/envelope/\" "+
         "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
         "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 
         authenticationHeader+
         "<soap:Body>" + 
         // Specify the RetrieveMultiple message.
         "<RetrieveMultiple xmlns="+
         "\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
         // Specify that this is a QueryByAttribute query.
         "<query xmlns:q1="+
         "\"http://schemas.microsoft.com/crm/2006/Query\" "+
         "xsi:type=\"q1:QueryByAttribute\">" + 
         // Query the customeraddress entity.
         "<q1:EntityName>erm_companyrole</q1:EntityName>" + 
         // Set the columns you want to return.
         "<q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
         "<q1:Attributes>" + 
         "<q1:Attribute>erm_name</q1:Attribute>" + 
         "</q1:Attributes>" + 
         "</q1:ColumnSet>" + 
         // Specify the attribute that you are querying on.
         "<q1:Attributes>" + 
         "<q1:Attribute>erm_companyroleid</q1:Attribute>" + 
         "</q1:Attributes>" + 
         // Set the value of the attribute using the customerid 
         // value of the case record.
         "<q1:Values>" + 
         "<q1:Value xsi:type=\"xsd:string\">"+
         guidSource.text+
         "</q1:Value>" + 
         "</q1:Values>" + 
         "</query>" + 
         "</RetrieveMultiple>" + 
         "</soap:Body>" + 
         "</soap:Envelope>";
         
        xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
        xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
        xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
        xmlHttpRequest.send(xml);
        doc = xmlHttpRequest.responseXML;
        var role = doc.selectSingleNode("//BusinessEntity");
        var roleName = role.childNodes[0];
        
        var lookupItem = new Array();
        lookupItem[0] = new Object();
        
        lookupItem[0].name = roleName.text;
        lookupItem[0].entityType = "erm_companyrole";
        lookupItem[0].id = guidRSource.text;
        
        Xrm.Page.getAttribute("erm_valutatorroleid").setValue(lookupItem);
        
    }		    
}

【问题讨论】:

  • 只是一个意见,但如果您想为 CRM 2016 及以后做好准备,您应该放弃 SOAP 端点请求并切换到 ODATA 端点。
  • @Filburt 我愿意切换到 ODATA,但我之前没有使用过 ODATA。我想要一种标准格式来使用 fetchXML 管理 CRM 2016 中的用户角色。这就是我能想到的。

标签: javascript dynamics-crm-2011 dynamics-crm fetchxml


【解决方案1】:

您的查询正在使用已弃用的 Dynamics CRM 4.0 Web 服务端点。从 SOAP 消息中删除身份验证标头,并将端点地址 "/mscrmservices/2007/CrmService.asmx" 替换为 "xrmservices/2011/organization.svc/web"。一个很好的例子可以在here找到。

随着在 Dynamics CRM 2016 中引入 Web API,Microsoft 完全取消了 SOAP 端点,但承诺在未来几年继续支持它。

【讨论】:

  • 我知道了。但我想将 CRM 4.0 表格更新为 CRM 2015。xrmservices/2011/organization.svc/web 用于 CRM 2011,我想将其转换为 ODATA,但我没有知道锄头去适应它。
  • xrmservices/2011/organization.svc` 是在 CRM 2011 中引入的,是迄今为止唯一的 CRM SOAP 端点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-14
  • 2011-08-18
  • 1970-01-01
  • 1970-01-01
  • 2012-12-28
  • 2013-05-08
  • 1970-01-01
相关资源
最近更新 更多