SyntaxError: Failed to execute 'querySelector' on 'Document': '[object HTMLDocument]' is not a valid selector
Asked Answered
Z

1

6

I am trying to get all field values from a sharepoint list item on a display template, the ctx.CurrentItem only gets some values but not all I need.

I tried the following code, but I get the error on the title

SyntaxError: Failed to execute 'querySelector' on 'Document': '[object HTMLDocument]' is not a valid selector.

function GetListItemById_Success(sender, args) 
{ 
   var id = ListItem.get_id(); 
   var title = ListItem.get_item("Title"); 
   alert("Updated List Item: \n Id: " + id + " \n Title: " + title); 
}

// Display an appropriate error message 
function GetListItemById_Fail(sender, args) 
{ 
   alert("GetListItemById Failed. \n" + args.get_message() + "\n" + args.get_stackTrace());
}

$(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(CustomAction, "sp.js"); });

function CustomAction(){
var clientContext =  new SP.ClientContext.get_current();
var web = clientContext .get_web(); 
var targetList = clientContext.get_web().get_lists().getByTitle('Test Document Library');
var list = web.get_lists().getByTitle('Test Document Library'); 
ListItem = list.getItemById(ctx.CurrentItem.DocId);
clientContext.load(ListItem, "Id", "Title"); 
clientContext.executeQueryAsync(GetListItemById_Success, GetListItemById_Fail); 
}
Zagreus answered 22/3, 2014 at 12:46 Comment(0)
T
1

I got the same exception after upgrading jQuery located in top level site. The reason was reference to old jQuery library in subsite master page.

Togoland answered 13/6, 2014 at 12:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.