javascript - CRM 身份验证问题

标签 javascript dynamics-crm

如何在 JavaScript 中包含GenerateAuthenticationHeader()。我需要包含哪些必要的 DLL?我使用此函数通过 JavaScript 检索 MS CRM 实体。我收到此错误:

Microsoft JScript runtime error: 'GenerateAuthenticationHeader' is undefined

function AccessCRMWebServices() {
        debugger;
        var auth = GenerateAuthenticationHeader();
                    var productCode = "ABCDE";
                    var stock;
                    var x = Xrm.Page.getAuthenticationHeader();
                    var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical">';
                    // Target Entity Name
                    fetchXml += '<entity name="new_aditya_products">';
                    // Required Attribute
                    fetchXml += '<attribute name="new_productname"/>';
                    fetchXml += '<attribute name="new_name"/>';
                    // Condition
                    fetchXml += '<filter type="and">';
                    fetchXml += '<condition attribute="new_productcode" operator="eq" value="' + productCode + '" />';
                    fetchXml += '</filter>';

                    fetchXml += '</entity>';
                    fetchXml += '</fetch>';

                    var Xml = "<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\">"
                    Xml += GenerateAuthenticationHeader()
                    Xml += "<soap:Body>";
                    Xml += "<Fetch xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">";
                    Xml += "<fetchXml>";
                    //Xml += _HtmlEncode(fetchXml);
                    Xml += "</fetchXml>";
                    Xml += "</Fetch>";
                    Xml += "</soap:Body>";
                    Xml += "</soap:Envelope>";

                    var XmlHttp = CreateXmlHttp();

                    XmlHttp.open("POST", 'http://rxdotnet:5555/MSCRMServices/2007/MetadataService.asmx', false);
                    XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                    XmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
                    XmlHttp.send(Xml);
                    var resultDoc = loadXmlDocument(XmlHttp.responseXML.text);
                    var resultRecords = resultDoc.selectNodes("//stockvolume");
                    var resultnames = resultDoc.selectNodes("//new_name");
                    if (resultRecords.length == 1) {
                        stock = resultRecords[0].text;
                        alert('Product ' + resultnames[0].text + ' Contains stock is -' + stock);
                    }

最佳答案

我假设您使用的是 MS CRM 4.0 版

GenerateAuthenticationHeader 函数只能在表单代码中本地使用(如 SDK 中所述,它是一个全局函数)。我相信在任何其他情况下使用它都是不支持的。这就是您收到错误的原因。

它所做的一切,按照SDK的方法是创建一个如下所示的 SOAP header (因此也许您可以在代码中重新创建它):

<soap:Header>
<CrmAuthenticationToken xmlns="http://schemas.microsoft.com/crm/2007/WebServices">
  <AuthenticationType xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
    0
  </AuthenticationType>
  <OrganizationName xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
    AdventureWorksCycle
  </OrganizationName>
  <CallerId xmlns="http://schemas.microsoft.com/crm/2007/CoreTypes">
    00000000-0000-0000-0000-000000000000
  </CallerId>
</CrmAuthenticationToken>
</soap:Header>

除此之外,可能还有其他解决方案。您想做什么以及您的代码在哪里运行?

关于javascript - CRM 身份验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12177120/

相关文章:

dynamics-crm - 客户关系管理 2013 : How can I Schedule Concurrent Appointments (using Appointment & RecurringAppointmentMaster entities)?

c# - 如何使用 CrmServiceClient 设置空属性值

javascript - 在 Dynamics 365 和 JavaScript 中显示相关实体

javascript - 使用 Web API 将实体列表填充到 HTML 页面加载的下拉列表中

javascript - 如何使用 javascript 将 blob 作为文件发布?

java - 我如何在opengl中画一个半圆

javascript - @babel/typescript 在 webpack 构建时不会抛出错误

php - 如何在新窗口中打开 PHP/表单结果页面?

c# - 用于查找值的 Dynamics 365 插件

javascript - 将 JavaScript 排入 Wordpress 插件