gpt4 book ai didi

javascript - 我如何为 CRM 2011 UR 12 重新制作 FetchUtil.js

转载 作者:行者123 更新时间:2023-11-29 18:24:15 27 4
gpt4 key购买 nike

我必须重新制作 FetchUtil.js 才能在 CRM 2011 UR 12 中使用它。我的 javascript 不是很好,所以我需要一些帮助。

这是原生代码

 var sFetchResult = xmlhttp.responseXML.selectSingleNode("//a:Entities").xml;
var resultDoc = new ActiveXObject("Microsoft.XMLDOM");
resultDoc.async = false;
resultDoc.loadXML(sFetchResult);

它现在甚至在 IE 中也不起作用,因为 .selectSingleNode("//a:Entities").xml我是这样做的,但是那里没有 xml 字段。

sFetchResult = xmlhttp.responseXML.getElementsByTagName('a:Entities')[0].xml;
var resultDoc = new ActiveXObject("Microsoft.XMLDOM");
resultDoc.async = false;
resultDoc.loadXML(sFetchResult);

帮我为 IE 和 Chrome 重新制作这个。非常感谢!

最佳答案

这是我的调用模块(包含为网络资源)

(function (module, undefined) {

module.buildFetchRequest = function (fetch) {
/// <summary>
/// builds a properly formatted FetchXML request
/// based on Paul Way's blog post "Execute Fetch from JavaScript in CRM 2011"
/// http://blog.customereffective.com/blog/2011/05/execute-fetch-from-javascript-in-crm-2011.html
/// </summary>
var request = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
request += "<s:Body>";

request += '<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">' +
'<request i:type="b:RetrieveMultipleRequest" ' +
' xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" ' +
' xmlns:i="http://www.w3.org/2001/XMLSchema-instance">' +
'<b:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">' +
'<b:KeyValuePairOfstringanyType>' +
'<c:key>Query</c:key>' +
'<c:value i:type="b:FetchExpression">' +
'<b:Query>';

request += CrmEncodeDecode.CrmXmlEncode(fetch);

request += '</b:Query>' +
'</c:value>' +
'</b:KeyValuePairOfstringanyType>' +
'</b:Parameters>' +
'<b:RequestId i:nil="true"/>' +
'<b:RequestName>RetrieveMultiple</b:RequestName>' +
'</request>' +
'</Execute>';

request += '</s:Body></s:Envelope>';
return request;
};

module.sendFetchQuery = function (fetchRequest, doneCallback, failCallback) {
//path to CRM root
var server = window.location.protocol + "//" + window.location.host;

//full path to CRM organization service - you may need to modify this depending on your particular situation
var path = server + "/XRMServices/2011/Organization.svc/web";

$.ajax({
type: "POST",
dataType: 'xml',
async: false,
contentType: "text/xml; charset=utf-8",
processData: false,
url: path,
data: fetchRequest,
beforeSend: function (xhr) {
xhr.setRequestHeader(
"SOAPAction",
"http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute"
); //without the SOAPAction header, CRM will return a 500 error
}
}).done(doneCallback)
.fail(failCallback);

};

}(window.xFetch = window.xFetch || {}));

用法(解析器需要 jQuery ......我在网络资源 html 页面中执行我的大部分提取调用,所以这不是问题)这在 IE 和 Chrome 中有效没有检查 firefox 但我不明白为什么它不会'不工作。

   var fetchXml =
xFetch.buildFetchRequest("<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
" <entity name='ENTITYNAME'>" +
" <attribute name='ATTRIBUTE' />" +
" </entity>" +
"</fetch>");

var entityList = new Array();

xFetch.sendFetchQuery(fetchXml,
function (fetchResponse) {

// chrome doesn't like the namespaces because of
// selectSingleNode implementations (which make sense btw)
// I'll never understand why Microsoft have to pepper their xml
// with namespace dross
$(fetchResponse).find("a\\:Entity, Entity").each(function () {

var entityData = {};

$(this).find("a\\:KeyValuePairOfstringanyType, KeyValuePairOfstringanyType").each(function () {
var xmlElement = $(this);
var key = xmlElement.find("b\\:key, key").text();
var value = xmlElement.find("b\\:value, value").text();
entityData[key] = value;
});

//inner loop
$(this).find("a\\:KeyValuePairOfstringstring, KeyValuePairOfstringstring").each(function () {
var xmlElement = $(this);
var key = xmlElement.find("b\\:key, key").text();
var value = xmlElement.find("b\\:value, value").text();
entityData[key] = value;
});

entityList.push(entityData);
});

}, function (jqXhr, textStatus, errorThrown) {
// if unsuccessful, generate an error alert message
});


for (var i = 0; i < entityList.length; i++) {

if (entityList[i].ATTRIBUTE === "Yes" ){
// DO WHATEVER
}
}

我只需要具有 KeyValuePairOfstringstring 和 KeyValuePairOfstringanyType 的属性,但您可以使用正确的选择器组合解析出任何属性

检索到的每个项目

关于javascript - 我如何为 CRM 2011 UR 12 重新制作 FetchUtil.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15180263/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com