0

JavaScriptにGenerateAuthenticationHeader()を含める方法。含める必要のある必要なDLLは何ですか?JavaScriptを使用してMSCRMエンティティを取得するためにこの関数を使用しています。このエラーが発生します:

Microsoft JScriptランタイムエラー:「GenerateAuthenticationHeader」は未定義です

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);
                    }
4

1 に答える 1

2

MSCRMバージョン4.0を使用していると想定しています

このGenerateAuthenticationHeader関数は、フォームコード内からのみネイティブに使用できます(SDKに記載されているグローバル関数です)。他のコンテキストで使用することはサポートされていないと思います。そのため、エラーが発生します。

SDKに従って、次のようなSOAPヘッダーを作成するだけです(コードで再作成できる可能性があります)。

<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>

これ以外に別の解決策があるかもしれません。あなたは何をしようとしていますか、そしてあなたのコードはどこで実行されていますか?

于 2012-08-29T12:52:55.100 に答える