I am using this custom display template with a search results web query to roll up tasks. http://www.surfray.com/blog/2013/06/12/aggregate-your-open-tasks-with-sharepoint-2013/

I have followed the instructions as per the blog but when I click on the link to the task it returns me to the home page. The fault is with the display template ( I think)

The js should construct the url to the list item

<a title="Open task" style="cursor:pointer" href="#" onclick="javascript:var domain=window.location.protocol + '//' + window.location.host;var title='_#=ctx.CurrentItem.Title=#_';var path='_#=ctx.CurrentItem.Path=#_';if(path.indexOf(domain)===0){SP.SOD.executeFunc('sp.ui.dialog.js', null, function () { SP.UI.ModalDialog.showModalDialog({width: 600, height: 338, allowMaximize: true, title: title, url: path, dialogReturnValueCallback: function (dialogResult, returnValue) { alert('NOTE: Changes to tasks are effective immediately, but will not appear in search results for a few minutes.');SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK); }});});}else{var response=confirm('This task is in another domain so it cannot be displayed here due to security restrictions in the browser. Do you want to leave this page to view the task?');if(response===true){window.location.href=path;}}">_#=ctx.CurrentItem.Title=#_</a><br />
                <span>Assigned To: _#=ctx.CurrentItem.AssignedTo=#_</span><br />

When the item is selected I get the home page and # from href='#'. How can get the url for the list item ? Is there a current item parameter?

The display template source is from here http://www.surfray.com/blog/wp-content/uploads/2013/06/Tasks_Custom.rar

Display template and JS newbie so any help would be great!

1 Answer 1


You mean ctx.CurrentItem.Path? It will spit out something like http://sharepoint/sites/sitecoll/Lists/listname/DispForm.aspx?ID=1

Why not set the href to ctx.CurrentItem.Path instead of #?

Check this out for all the properties you can get: http://sadomovalex.blogspot.com/2013/06/enumerate-all-properties-of-javascript.html


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.