Custom Action on Addanapp.aspx not executing

%3CLINGO-SUB%20id%3D%22lingo-sub-182905%22%20slang%3D%22en-US%22%3ECustom%20Action%20on%20Addanapp.aspx%20not%20executing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-182905%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20started%20to%20try%20and%20understand%20Scriptlink%20Custom%20Actions%20and%20as%20a%20bit%20of%20a%20test%2C%20I%20want%20to%20hide%20some%20elements%20on%20the%26nbsp%3Baddanapp.aspx%20page.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIndividually%2C%20I%20have%20managed%20to%20test%20each%20line%20of%20the%20elements%20in%20a%20Browser%20Developer%20Tools%20session%20and%20they%20hide%20as%20expected%20when%20executed%20individually.%26nbsp%3BHowever%2C%20none%20of%20them%20are%20firing%20when%20I%20reference%20the%20following%20code%20from%20my%20Custom%20Action%20JS%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAm%20I%20missing%20something%20obvious%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3Evar%3C%2FSPAN%3E%20%3CSPAN%3EjQuery%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3E%22%3CA%20href%3D%22https%3A%2F%2Fajax.aspnetcdn.com%2Fajax%2FjQuery%2Fjquery-2.0.2.min.js%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fajax.aspnetcdn.com%2Fajax%2FjQuery%2Fjquery-2.0.2.min.js%3C%2FA%3E%22%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%2F%2F%20Is%20MDS%20enabled%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%20(%3C%2FSPAN%3E%3CSPAN%3E%22undefined%22%3C%2FSPAN%3E%20%3CSPAN%3E!%3D%3C%2FSPAN%3E%20%3CSPAN%3Etypeof%3C%2FSPAN%3E%20%3CSPAN%3Eg_MinimalDownload%3C%2FSPAN%3E%20%3CSPAN%3E%26amp%3B%26amp%3B%3C%2FSPAN%3E%20%3CSPAN%3Eg_MinimalDownload%3C%2FSPAN%3E%20%3CSPAN%3E%26amp%3B%26amp%3B%3C%2FSPAN%3E%3CSPAN%3E%20(%3C%2FSPAN%3E%3CSPAN%3Ewindow%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Elocation%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Epathname%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EtoLowerCase%3C%2FSPAN%3E%3CSPAN%3E()).%3C%2FSPAN%3E%3CSPAN%3EendsWith%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22%2F_layouts%2F15%2Fstart.aspx%22%3C%2FSPAN%3E%3CSPAN%3E)%20%3C%2FSPAN%3E%3CSPAN%3E%26amp%3B%26amp%3B%3C%2FSPAN%3E%20%3CSPAN%3E%22undefined%22%3C%2FSPAN%3E%20%3CSPAN%3E!%3D%3C%2FSPAN%3E%20%3CSPAN%3Etypeof%3C%2FSPAN%3E%20%3CSPAN%3EasyncDeltaManager%3C%2FSPAN%3E%3CSPAN%3E)%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F%2F%20Register%20script%20for%20MDS%20if%20possible%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ERegisterModuleInit%3C%2FSPAN%3E%3CSPAN%3E(%3C%2F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C%2FSPAN%3E%3CSPAN%3E%20()%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ESP%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3ESOD%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EexecuteOrDelayUntilScriptLoaded%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3Efunction%3C%2FSPAN%3E%3CSPAN%3E%20()%20%7B%20%3C%2FSPAN%3E%3CSPAN%3ESetStatusBar%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3Emessage%3C%2FSPAN%3E%3CSPAN%3E)%3B%20%7D%2C%20%3C%2FSPAN%3E%3CSPAN%3E'sp.js'%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F%2F%20Customize%20the%20addanapp.aspx%20page%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%20(%3C%2FSPAN%3E%3CSPAN%3EIsOnPage%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22addanapp.aspx%22%3C%2FSPAN%3E%3CSPAN%3E))%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F%2Fhide%20the%20search%20apps%20field%20and%20label%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22%23idStorefrontHeader%22%3C%2FSPAN%3E%3CSPAN%3E).%3C%2FSPAN%3E%3CSPAN%3Ehide%3C%2FSPAN%3E%3CSPAN%3E()%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%24%3C%2FSPAN%3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3C%2FSPAN%3E%3CSPAN%3EpageName%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EtoLowerCase%3C%2FSPAN%3E%3CSPAN%3E())%20%3C%2FSPAN%3E%3CSPAN%3E%26gt%3B%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3E1%3C%2FSPAN%3E%3CSPAN%3E)%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ereturn%3C%2FSPAN%3E%20%3CSPAN%3Etrue%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%20%3C%2FSPAN%3E%3CSPAN%3Eelse%3C%2FSPAN%3E%3CSPAN%3E%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ereturn%3C%2FSPAN%3E%20%3CSPAN%3Efalse%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-182905%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Ecustom%20action%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2417176%22%20slang%3D%22en-US%22%3ERe%3A%20Custom%20Action%20on%20Addanapp.aspx%20not%20executing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2417176%22%20slang%3D%22en-US%22%3E%3CP%3Elittle%20late%20to%20it%2C%20but%20you'll%20want%20to%20wait%20until%20the%20page%20loads%20before%20your%20script%20executes.%3C%2FP%3E%3CP%3Esee%20what%20sort%20of%20JS%20promise%20chain%20you%20need%20to%20jump%20into%20as%20the%20elements%20are%20not%20yet%20rendered%20when%20your%20script%20executes.%20a%20simple%20script%20delay%20works%20but%20a%20promise%20chain%20would%20be%20ideal%20to%20ensure%20you%20target%20what%20you%20want%20to%20hide%20AFTER%20it%20gets%20rendered.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New 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.