gpt4 book ai didi

javascript - 如何使用 rest(使用 CAML)在共享点列表中的超链接列上应用过滤器?

转载 作者:行者123 更新时间:2023-11-30 20:49:42 24 4
gpt4 key购买 nike

我想获取 siteUrl 包含来自变量“project_url”的值的项目

var project_url = _spPageContextInfo.webServerRelativeUrl;

var queryText = "<Where><Contains><FieldRef Name='SiteUrl' /><Value Type='URL'>" + project_url + "</Value></Contains></Where>";

var viewXml = '<View><Query>' + queryText + '</Query></View>';
var webserviceUrl = _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists(guid'eb0ba220-73e8-428f-b848-92b606aa74d8')/items?$select=ID,Title,MembersId,AccessTYpe,OrganizationalUnitId,SiteUrl";

var queryPayload = {
'query' : {
'__metadata': { 'type': 'SP.CamlQuery' },
'ViewXml' : viewXml,
}
};

$.ajax({
url: webserviceUrl,
method: "POST",
data: JSON.stringify(queryPayload),
headers: {
"X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
"Accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
},
success: function (data) {
console.log(data);
},
error: function (data) {
console.log("AllTasks Error -", data);
}
});

我收到这个错误:

'"{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"An entry without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified."}}}"'

最佳答案

您需要点击 GetItems 端点。

此外,将 CAML 查询更改为使用 BeginsWith 而不是 Contains

修改你的代码如下:

var project_url = _spPageContextInfo.webAbsoluteUrl;

var queryText = "<Where><BeginsWith><FieldRef Name='SiteUrl' /><Value Type='URL'>" + project_url + "</Value></BeginsWith></Where>";

var viewXml = '<View><Query>' + queryText + '</Query></View>';
var webserviceUrl = _spPageContextInfo.siteAbsoluteUrl + "/_api/web/Lists(guid'eb0ba220-73e8-428f-b848-92b606aa74d8')/GetItems";

var queryPayload = {
'query' : {
'__metadata': { 'type': 'SP.CamlQuery' },
'ViewXml' : viewXml,
}
};

$.ajax({
url: webserviceUrl,
method: "POST",
data: JSON.stringify(queryPayload),
headers: {
"X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
"Accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
},
success: function (data) {
console.log(data);
},
error: function (data) {
console.log("AllTasks Error -", data);
}
});

关于javascript - 如何使用 rest(使用 CAML)在共享点列表中的超链接列上应用过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48318700/

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