Apr 03 2017 12:32 AM
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
Apr 03 2017 01:03 AM
SolutionAs 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.
Apr 03 2017 02:19 PM
Thanks Paul - you're a machine!