OBJECTIVE: Add a button to standard DispForm.aspx to do anything.
COMPONENTS: SharePoint 2016 OnPrem, OOB Dispform.aspx of an OOB Tasks list.
So far, have added the button to the page by creating an .html and linking to a CEWP.
<button onclick="populateTasks()">Populate Template Tasks</button>
<p id="msgbox">Click this button to populate tasks</p>
Created a .js file, linked via the JSLink, to try to do anything simple, like, show an alert, update text on the page, or open another page.
function populateTasks() {
console.log("got here");
if ( confirm("Are you sure?") ) {
var vParameterVal = "Button was clicked"
var href = window.location.href;
var url = new URL(href);
var vParameterName = "id";
vParameterVal = url.searchParams.get(vParameterName);
document.getElementById("msgbox").innerHTML = vParameterVal;
window.location.replace("https://icenter.saic.com/sites/peess/main/projsiteex/Lists/Tasks/EditForm.aspx?ID=" + vParameterVal);
}
}
None of the reports from this code trigger. It doesn't fire the confirm, update console.log, update the msgbox div, nor redirect to another page.
What need to happen to make this button do anything?
TIA