Click here to Skip to main content
14,108,747 members
Rate this:
 
Please Sign up or sign in to vote.
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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");
}
});
}
   
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You can try this way

/_api/web/lists/GetByTitle('TestReference')/items?$expand=LookupColumn&$select=Title,LookupColumn/Title&$filter=substringof('A',LookupColumn/Title)
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190518.1 | Last Updated 13 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100