gpt4 book ai didi

javascript - 通过 IFrame 查询 ODATA 端点时接收 Windows 安全对话框

转载 作者:行者123 更新时间:2023-11-29 15:01:54 26 4
gpt4 key购买 nike

我正在使用 IFD CRM2011 环境,我正在关注 this MSDN example查询 ODATA 端点以填充 IFrame 中的下拉菜单。

这是填充下拉列表的代码:

function GetQuestionSetList() {
var query = '/Mhc_questionsetverSet?' +
'$select=Mhc_name,Mhc_questionsetverId&$filter=statecode/Value eq 0';
SDK.RestEndpointPaging
.RetrieveRecords(query, ProcessReturnedQuestionSetVersions);
}

function ProcessReturnedQuestionSetVersions(retrievedQuestionSets) {
for (var i = 0; i < retrievedQuestionSets.length; i++) {
var questionSet = retrievedQuestionSets[i];
var value = questionSet.Mhc_questionsetverId;
var name = questionSet.Mhc_name;

//add option to select list
$('#selectQuestionSetVersion').append($('<option>')
.attr('value', value)
.text(name));
}
}

SDK.RestEndpointPaging.RetrieveRecords(query, ProcessReturnedQuestionSetVersions); 行执行后,我收到此对话框的提示:

enter image description here

此时我可以输入我的凭据或按取消并填充下拉列表。在开发人员工具中,我在两种情况下都注意到了这个错误:

SCRIPT5022: Exception thrown and not caught

mhc_json2.js, line 484 character 13

// If the text is not JSON parseable, then a SyntaxError is thrown.

throw new SyntaxError('JSON.parse'); //line 484
};
}
}());

我不明白为什么会出现这个对话框或者为什么会抛出这个错误。

最佳答案

发完这个后,正好查了一下fiddler,发现了问题。在我的情况下,有两次调用 RetrieveRecords。第一个调用返回状态 200(成功),但第二个调用返回 401。

这是两个调用:

https://alpha.ftg.com:5556//xrmservices/2011/organizationdata.svc/Mhc_questionsetverSet?$select=Mhc_name,Mhc_questionsetverId&$filter=statecode/Value eq 0

https://alpha.ftg.com:5556//xrmservices/2011/organizationdata.svchttps://alpha.ftg.com:5556/xrmservices/2011/organizationdata.svc/Mhc_questionsetverSet?$filter=statecode/Value%20eq%200&$select=Mhc_name,Mhc_questionsetverId&$skiptoken=1,'mhc_questionsetverid','%7B3F737386-54DF-DE11-A55C-00155D020C0D%7D','%7B7AF1B564-C3BF-DD11-8209-000BCDC54FC9%7D'

在第二次调用中,服务器 + odata 端点连接了两次。如果找到 __next 参数,则 RetrieveRecordsCallback 函数应该去除服务器和端点 url,如下所示:

MSDN explanation:

If a __next property is found the new URL with a $skiptoken is passed back to SDK.RestEndpointPaging.RetrieveRecords as the new filter parameter value so that the process is repeated for each set of records until the total >number of requested records is retrieved and the __next property is no longer returned.

if (null != retrievedRecords.__next) {
// The existance of the '__next' property
//indicates that more records are available
// So the originating function is called again
//using the filter value returned
var filter = retrievedRecords.__next
.replace(SDK.RestEndpointPaging.GetODataPath(), "");
SDK.RestEndpointPaging.RetrieveRecords(filter, callback);
}

SDK.RestEndpointPaging.GetODataPath() 在 url 的服务器和端点部分之间附加了一个额外的 /,但是当返回新的过滤器参数时,额外的/ 已被删除,因此 .replace 函数无法替换路径,它会被第二次追加。

修复很简单。只需将 SDK.RestEndpointPaging.GetODataPath() 函数更改为:

 GetODataPath: function () {
/// <summary>
/// Utility function to retrieve the path to the REST endpoint.
/// </summary>
var serverUrl = Xrm.Page.context.getServerUrl();

//remove the extra '/' char if it exists
if (serverUrl.match(/\/$/)) {
serverUrl = serverUrl.substring(0, serverUrl.length - 1);
}

return serverUrl + "/xrmservices/2011/organizationdata.svc";
},

关于javascript - 通过 IFrame 查询 ODATA 端点时接收 Windows 安全对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8750266/

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