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

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

Here we will discuss how we can remove items from the Site Actions menu using JavaScript object model (jsom) in SharePoint Online Office 365. In my previous posts, we have discussed how we can add an item to the 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 the Site Actions menu using JavaScript object model

Hope this will be helpful.


You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply