Sharepoint REST API筛选器空查找字段
问题描述:
我想知道如何在空查找中筛选SharePoint rest API中的ListItems(2013)。 在我的列表项目中,有一个查找(单个值,不是必需的),我想要查找空的所有项目(空白)。Sharepoint REST API筛选器空查找字段
_api/web/lists/getbytitle('MyList')/items?$select=Id&$expand=MyLookUp/Id&$filter=??
有人有线索吗?
THX
答
在SharePoint 2013 REST API不支持null值列表项过滤查询。
但是,您可以将CAML查询与REST API结合使用以获取所需的数据。
请参考下面的代码: (注:请更改您的查询/ URL):
function _rest_Post(rquest) {
return $.ajax({
method: rquest.method,
url: rquest.url,
contentType: rquest.contentType,
headers: rquest.header,
data: JSON.stringify(rquest.body),
});
}
function GetByCaml(serviceParams) {
var req = {
method: 'POST',
url: url + "/_api/web/lists/getByTitle('" + serviceParams.create.lName + "')/getitems",
header: {
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose"
},
body: serviceParams.create.body,
contentType: "application/json;odata=verbose",
};
return _rest_Post(req);
}
function getData(){
var queryViewXml = "<View><Query><Where><IsNull><FieldRef Name='Project_x0020_Manager'/></IsNull></Where></Query><ViewFields><FieldRef Name='Title'/></ViewFields></View>";
var params = {};
params.create= {};
params.create.lName = "MyList";
params.create.filter = "";
params.create.body = {
'query':{
'__metadata': { 'type': 'SP.CamlQuery' },
'ViewXml': queryViewXml
}
}
return GetByCaml(params);
};
getData().then(function(data){
//success handler
}, function(error){
//failure handler
});
答
OP,你的答案是非常接近。空查找的Id值应为-1。如果您使用SP CAML查询帮助程序探索原始数据,则应在未选中的查找中看到-1;#。
/项目/?$选择= ID,标题,Assigned_x0020_To /编号& $扩大= Assigned_x0020_To & $过滤=(Assigned_x0020_To EQ -1)应该为你工作。
答
我刚刚发现了一个使用REST工作的解决方案,您只需将查找ID过滤为大于0.所有查找ID均为1或更大,但使用不等于0(MyLookup ne 0)失败,因为null为不等于0.但是,null显然不会大于0。这可能会使数学怪才抽搐,但它的工作。
_api/web/lists/getbytitle('abc')/items?$select=Id&$expand=MyLookUp/Id&$filter=MyLookup gt 0