I'm trying to write a query using the JSOM to get the last document uploaded to a document library by the current user. The reason I'm doing this is because I have an upload button on a form and need to have a way to get a reference to the document after it's uploaded and display a link to it on the page. So I have this code and it's failing with an "unable to complete this request - undefined" error:

//query for the last uploaded item by this user
var clientContext = new SP.ClientContext('example.com');
var oList = clientContext.get_web().get_lists().getByTitle('List Title'); 
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><RowLimit>1</RowLimit><Query><Where><Eq><FieldRef Name="Editor" /><Value Type="User">domain\\user</Value></Eq></Where><OrderBy><FieldRef Name="Modified" Ascending="False"></OrderBy></Query></View>');
this.collListItem = oList.getItems(camlQuery);   
clientContext.load(collListItem, 'Include(Id, Name)'); 
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

Am I going about this the right way? Amy I using CAML syntax incorrectly? I'm really new to SharePoint and unsure if this is even the proper way to get a reference to this document. I'm having the user upload it by using the Upload.aspx form in a modal dialog and haven't found a way to just return the document from the modal.

1 Answer 1


Query should be like below

  <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
        <FieldRef Name="Author"/>
        <Value Type="User">Display Name</Value>

Make sure you are using Display Name and not Domain User Name

  • I would suggest considering using <FieldRef Name="Author" /><Value Type="Integer"><UserID /></Value> in case some users happen to have the same Display Name.
    – user2536
    May 18, 2015 at 8:31

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.