Remove items from Site Actions menu using JavaScript object model in SharePoint Online Office 365

Remove items from Site Actions menu using JavaScript object model
InfoPath alternatives for form designing SharePoint

Here we will discuss how we can remove items from Site Actions menu using JavaScript object model (jsom) in SharePoint Online Office 365. In my previous posts, we have discussed how we can add item to Site Actions menu in SharePoint online Office 365 using JavaScript object model (jsom).

Here in my SharePoint online site, I have added few items to the Site Actions menu like below:

Remove items from Site Actions menu using JavaScript object model
Remove items from Site Actions menu using JavaScript object model

Also read:
– SharePoint Online Site Workflow and Initiation Form Parameters example using SharePoint designer workflow

– Introduction to cloud computing and Microsoft Azure

– Create Custom Action Group using Visual Studio 2015 for SharePoint 2016

We can add the below jsom code inside a script editor web part which we can add into a web part page.

Below is the full code

<script language=”javascript” type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js”></script>
<script language=”javascript” type=”text/javascript”>
var customActions;
var clientContext;
$(document).ready(function() {
SP.SOD.executeFunc(‘sp.js’, ‘SP.ClientContext’, DeleteCustomMenuAction);
});

function DeleteCustomMenuAction() {
clientContext = new SP.ClientContext();
var web = clientContext.get_web();
customActions = web.get_userCustomActions();
clientContext.load(customActions);
clientContext.load(web);
clientContext.executeQueryAsync(OnSuccess, OnFailure);
}

function OnSuccess() {
var enumerator = customActions.getEnumerator();
var removeThese = []
while (enumerator.moveNext()) {
var action = enumerator.get_current();
alert(action.get_title());
if (action.get_title() == “Go to EnjoySharePoint”)
{
action.deleteObject();
}
clientContext.load(action);
clientContext.executeQueryAsync();
}
}

function OnFailure() {
alert(‘Fail’);
}
</script>

Once you add the code and execute, the menu items will be removed from the Site Actions menu.

SharePoint online Remove items from Site Actions menu using JavaScript object model

SharePoint online Remove items from Site Actions menu using JavaScript object model
SharePoint online Remove items from Site Actions menu using JavaScript object model

Hope this will be helpful.

Similar SharePoint 2013 Tutorials


Leave a Reply