SOLVED

Search REST query - filtering ModifiedBy by Current User

Iron Contributor

Hi,

 

Trying to show the 10 most recent documents edited by the current user by calling the search REST api, but I am struggling with filtering the results by the current user. Using this call gives 0 results:

 

/_api/search/query?querytext='(*)+AND+(path:"https:%2f%2fscentregroup.sharepoint.com%2fsites%2fcorplegal_dev")+AND+(FileExtension:doc+OR+FileExtension:docx+OR+FileExtension:ppt+OR+FileExtension:pptx+OR+FileExtension:xls+OR+FileExtension:xlsx+OR+FileExtension:xlsm+OR+FileExtension:pdf)'&trimduplicates=false&refinementfilters='ModifiedBy:{User.Name}'&clienttype='ContentSearchRegular'

 

However if I use my actual name, I get the expected set of results:

 

/_api/search/query?querytext='(*)+AND+(path:"https:%2f%2fscentregroup.sharepoint.com%2fsites%2fcorplegal_dev")+AND+(FileExtension:doc+OR+FileExtension:docx+OR+FileExtension:ppt+OR+FileExtension:pptx+OR+FileExtension:xls+OR+FileExtension:xlsx+OR+FileExtension:xlsm+OR+FileExtension:pdf)'&trimduplicates=false&refinementfilters='ModifiedBy:Nigel Witherdin'&clienttype='ContentSearchRegular'

 

Is there a token value I can use in this REST call, or should I be determining the current user's display name in the script myself and insert it into the REST call?

 

Thanks

 

Nigell

 

 

 

2 Replies
best response confirmed by Nigel Witherdin (Iron Contributor)
Solution

As described in this blog by @Mikael Svenson you can use Query Variables together with the REST api

http://www.techmikael.com/2015/07/sharepoint-rest-do-support-query.html

 

Key here is to make use of QueryTemplate instead of QueryText.

 

Thanks Paul - you're a machine!

1 best response

Accepted Solutions
best response confirmed by Nigel Witherdin (Iron Contributor)
Solution

As described in this blog by @Mikael Svenson you can use Query Variables together with the REST api

http://www.techmikael.com/2015/07/sharepoint-rest-do-support-query.html

 

Key here is to make use of QueryTemplate instead of QueryText.

 

View solution in original post