Kwizcom Forms

SharePoint Online: Add/Delete custom actions from Site Actions menu using JavaScript Object Model (jsom)

Add custom actions in Site Actions menu in SharePoint Online using JavaScript Object Model and Delete custom action menu option in Site Actions menu in SharePoint online using JavaScript Object Model

In this post, we will discuss how we can add custom actions menu options in Site Actions in SharePoint online using JavaScript Object Model and also we will discuss how we can delete custom action menu option in Site Actions menu in SharePoint online using JavaScript Object Model.

The menu will appear when you click on the gear icon.

SharePoint deveopment training course

You can use the below code inside a script editor web part.

Add custom actions in Site Actions menu SharePoint

<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>

<input name=”ADD” id=”btnAdd” type=”submit” value=”Add new custom actions” />

<script language=”javascript” type=”text/javascript”>

$(document).ready(function () {

$(“#btnAdd”).click(function () {

AddCustomActions();
});
});
function AddCustomActions() {
var clientContext = new SP.ClientContext();
var web=clientContext.get_web();
var customActions = web.get_userCustomActions();
var newCustomActionMenu = customActions.add();
newCustomActionMenu.set_location(‘Microsoft.SharePoint.StandardMenu’);
newCustomActionMenu.set_group(‘SiteActions’);
newCustomActionMenu.set_sequence(3000);
newCustomActionMenu.set_title(‘EnjoySharePoint.com’);
newCustomActionMenu.set_description(‘Go to EnjoySharePoint.com’);
newCustomActionMenu.set_url(‘http://www.enjoysharepoint.com’);
newCustomActionMenu.update();

clientContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
Function.createDelegate(this, this.onFailure));
}
function onSuccess() {
alert(‘New Item Added to Site Actions Menu’);
}
function onFailure(sender, args) {
alert(‘Error Occurred. ‘ + args.get_message());
}
</script>

Once you will add, it will come like below:

 Add custom actions in Site Actions menu in SharePoint Online using JavaScript Object Model and Delete custom action menu option in Site Actions menu in SharePoint online using JavaScript Object Model
Add custom actions in Site Actions menu in SharePoint Online using JavaScript Object Model

Delete custom action menu option in Site Actions menu

Below is the code which will delete custom actions menu options in SharePoint.

<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>

<input name=”Delete” id=”btnDelete” type=”submit” value=”Delete custom actions” />

<script language=”javascript” type=”text/javascript”>
var customActions;
var clientContext;
$(document).ready(function () {

$(“#btnDelete”).click(function () {

DeleteCustomActions();
});
});
function DeleteCustomActions() {
clientContext = new SP.ClientContext();
var web=clientContext.get_web();
customActions = web.get_userCustomActions();
clientContext.load(web, ‘UserCustomActions’, ‘Title’);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
Function.createDelegate(this, this.onFailure));
}
function onSuccess() {
var customActionEnumerator = customActions.getEnumerator();
while (customActionEnumerator.moveNext())
{
var oUserCustomAction = customActionEnumerator.get_current();
alert(oUserCustomAction.get_title());
if (oUserCustomAction.get_title() == ‘EnjoySharePoint.com’)
{
oUserCustomAction.deleteObject();
clientContext.load(oUserCustomAction);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededdelete), Function.createDelegate(this, this.onQueryFailed));
}
}
}
function onQuerySucceededdelete()
{
alert(‘Custom Actions Deleted Successfully’);
}
function onQueryFailed(sender, args) {
alert(‘Error Occurred. ‘ + args.get_message()+ ‘\n’ + args.get_stackTrace());
}
function onFailure(sender, args) {
alert(‘Error Occurred. ‘ + args.get_message());
}
</script>

You can see like below the menu will be removed.

 Add custom actions in Site Actions menu in SharePoint Online using JavaScript Object Model and Delete custom action menu option in Site Actions menu in SharePoint online using JavaScript Object Model
delete custom actions in Site Actions menu in SharePoint Online using JavaScript Object Model

You may like following SharePoint tutorials:

Hope this will be helpful to Add custom actions in the Site Actions menu in SharePoint Online using JavaScript Object Model and delete custom actions in the Site Actions menu in SharePoint Online using JavaScript Object Model (jsom).

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

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 →