Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I have a SharePoint list as below.

<
col1	col2	col3
India	Sudha	Yellow
Africa	Ajay	Green
America	Vijay	Red
>

col1 is a lookup field.
I want to use Rest API and filter the list on a col1 in such a way that even if i give part of the string, it should search the record.

I tried "
https://sharepoint.com/sites/sitename/_api/web/lists/GetByTitle('listname')/items?$expand=lookupcolumn&$select=Title,parentlookupcol/lookupcolumn&$filter=substringof('US2017 - 0002',lookupcolumn) 
", but no luck.

When i replace substring and use filter = lookup/col eq 'value' , i was able to search. But "eq" will look for complete string match which fails my requirement.

Appreciate your help.

Thanks in Advance
Naina

What I have tried:

I tried "<pre>https://sharepoint.com/sites/sitename/_api/web/lists/GetByTitle('listname')/items?$expand=lookupcolumn&$select=Title,parentlookupcol/lookupcolumn&$filter=substringof('US2017 - 0002',lookupcolumn) 
", but no luck.
Posted
Updated 13-Feb-19 0:41am

You can try this way

/_api/web/lists/GetByTitle('TestReference')/items?$expand=LookupColumn&$select=Title,LookupColumn/Title&$filter=substringof('A',LookupColumn/Title)
 
Share this answer
 
function GetListData(select)
{
var siteURL = _spPageContextInfo.webAbsoluteUrl;
var listname = "MyListName";
var currentUserId=_spPageContextInfo.userId; //is a user number Then needs to use /ID
var url = siteURL + "/_api/web/lists/getbytitle('" + listname + "')/items?$select=ID,Name,Title,MyUserField/ID&$filter=substringof('"+currentUserId+"',MyUserField/ID)&$expand=MyUserField/ID";


$.ajax({
url: url,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {

var items = data.d.results;
alert(items.length);

for(var i = 0; i < items.length;i++) {
var item=items[i];

//console.log(item.Title);
}
},
error: function (data) {
alert("error");
}
});
}
 
Share this answer
 
Comments
CHill60 13-Feb-19 7:17am    
Unformatted code dumps without any words of explanation are not very helpful and usually get down-voted. Why is your solution better than solution 1 which also pointed out the use of substringof - which is a lot clearer as that is the only line of code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900