AnswerBun.com

Search REST API for documents modified by logged in user

I am working on a query to get the documents modifies by logged in user. I am able to get the documents with the specific file extension.

var myurl = _spPageContextInfo.webAbsoluteUrl + '/_api/search/query?'+
"Querytext='* AND " +
    "(FileExtension:doc OR FileExtension:docx OR FileExtension:ppt OR FileExtension:pptx OR FileExtension:xls OR FileExtension:xlsx OR FileExtension:pdf OR ContentTypeId:0x010100F3754F12A9B6490D9622A01FE9D8F012*)'"+
'&sortlist='LastModifiedTime:descending'&RowLimit=10';

function onQuerySuccess2(data) {
    var results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
     $.each(results, function (index, result) {
            var modifiedTime = result.Cells.results[9].Value;
            console.log(modifiedTime);
     });
}

function onQueryError(error){
    console.log(error);
}

$.ajax({ url: myurl, method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: onQuerySuccess2, error: onQueryError });

The above piece of code is working properly. The only thing pending is to show the modified by currently logged in user. For this, I am adding the

&querytemplate=’modifiedby:{User}’

So my query becomes:

var myurl = _spPageContextInfo.webAbsoluteUrl + '/_api/search/query?'+
"Querytext='* AND " +
    "(FileExtension:doc OR FileExtension:docx OR FileExtension:ppt OR FileExtension:pptx OR FileExtension:xls OR FileExtension:xlsx OR FileExtension:pdf OR ContentTypeId:0x010100F3754F12A9B6490D9622A01FE9D8F012*)'"+
'&sortlist='LastModifiedTime:descending'&RowLimit=10&querytemplate='modifiedby:{User}'';

But then specific file extension filtering stops working. What am I doing wrong? any guess.?

SharePoint Asked on December 21, 2020

1 Answers

One Answer

Instead of specifying the querytext, you can directly specify it in the query template itself

Try and modify the below endpoint:

var myurl = _spPageContextInfo.webAbsoluteUrl + '/_api/search/query?'+
"queryTemplate='* ModifiedBy:{User} AND " +
    "(FileExtension:doc OR FileExtension:docx OR FileExtension:ppt OR FileExtension:pptx OR FileExtension:xls OR FileExtension:xlsx OR FileExtension:pdf OR ContentTypeId:0x010100F3754F12A9B6490D9622A01FE9D8F012*)'"+
'&sortlist='LastModifiedTime:descending'&RowLimit=10';

function onQuerySuccess2(data) {
    var results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
     $.each(results, function (index, result) {            
            var modifiedTime = result.Cells.results[9].Value;
            console.log(modifiedTime);
     });
}

function onQueryError(error){
    console.log(error);
}

$.ajax({ url: myurl, method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: onQuerySuccess2, error: onQueryError });

Answered by Gautam Sheth on December 21, 2020

Add your own answers!

Related Questions

Error creating SPFx with React JS

1  Asked on October 28, 2020 by tezz-chaudhary

   

Depolying SPFX Web Part on On Prem 2019

0  Asked on October 12, 2020 by kurt-cooney

       

Automate posting to SharePoint with Python

1  Asked on October 4, 2020 by brinley

 

Workflow updating a multiple value lookup column

1  Asked on October 3, 2020 by jl421

     

how to search people in search box in sharepoint 2013

1  Asked on September 6, 2020 by sharepointman

   

How to see checked out file

2  Asked on September 2, 2020 by dingo

 

SharePoint o365/online – This site can’t be reached

1  Asked on August 26, 2020 by rohit-waghela

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.