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);
}