Custom Action on Addanapp.aspx not executing

Copper Contributor

Hey all,

 

I've started to try and understand Scriptlink Custom Actions and as a bit of a test, I want to hide some elements on the addanapp.aspx page. 

 

Individually, I have managed to test each line of the elements in a Browser Developer Tools session and they hide as expected when executed individually. However, none of them are firing when I reference the following code from my Custom Action JS file.

 

Am I missing something obvious?

 


// Is MDS enabled?
if ("undefined" != typeof g_MinimalDownload && g_MinimalDownload && (window.location.pathname.toLowerCase()).endsWith("/_layouts/15/start.aspx") && "undefined" != typeof asyncDeltaManager) {
// Register script for MDS if possible
RegisterModuleInit("hideAddanApp.js", JavaScript_Embed); //MDS registration
JavaScript_Embed(); //non MDS run
} else {
JavaScript_Embed();
}

function JavaScript_Embed() {

loadScript(jQuery, function () {
$(document).ready(function () {
SP.SOD.executeOrDelayUntilScriptLoaded(function () { SetStatusBar(message); }, 'sp.js');
// Customize the addanapp.aspx page
if (IsOnPage("addanapp.aspx")) {
//hide the search apps field and label
$("#idStorefrontHeader").hide();
$("#idStorefrontListManageSorts").hide();
$("#idStorefrontListManageFilter").hide();
}
});
});
}

function SetStatusBar(message) {
var strStatusID = SP.UI.Status.addStatus("Information : ", message, true);
SP.UI.Status.setStatusPriColor(strStatusID, "yellow");
}

function IsOnPage(pageName) {
if (window.location.href.toLowerCase().indexOf(pageName.toLowerCase()) > -1) {
return true;
} else {
return false;
}
}

 

1 Reply

little late to it, but you'll want to wait until the page loads before your script executes.

see what sort of JS promise chain you need to jump into as the elements are not yet rendered when your script executes. a simple script delay works but a promise chain would be ideal to ensure you target what you want to hide AFTER it gets rendered.