2

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.?

1 Answer 1

0

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 });
1
  • hey @dilip, did you try the above code ? is it working for you ? Sep 15, 2017 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.