SharePoint user custom actions (Designer + Programmatically)

In this SharePoint tutorial, we will discuss SharePoint user custom actions. Also, we will see, how to add SharePoint user custom action using javascript and how to add custom actions using sharepoint designer 2013. We will see how to add SharePoint 2013 custom action list item menu.

Add custom actions to SharePoint list item menu using SharePoint Designer 2013

Now, let us see, how to add custom actions to list item menu using SharePoint Designer. We will see how to add custom actions to the list item menu using SharePoint Designer 2013 in SharePoint 2013 and how to add custom actions to the list item menu in SharePoint 2010 using SharePoint Designer 2010.

Add custom actions to list item menu using SharePoint Designer 2013

Check out the below image, in this example, we want to add an option to the list item ECB menu in SharePoint.

sharepoint user custom actions
sharepoint user custom actions

We can do this by using SharePoint designer 2013. Open the SharePoint site using SharePoint designer 2013. Then from the site objects select List and Libraries and then choose the particular list for which you want to add the menu.

When you will click on the list it will open the list settings page. In that page click on the Custom Actions menu as shown in the fig below:

Add custom actions to list item menu using SharePoint Designer 2013
sharepoint user custom action javascript

Then from the Ribbon click on Custom Action -> List Item Menu as shown in the fig below:

sharepoint 2013 custom action list item menu
sharepoint 2013 custom action list item menu

This will open the Create Custom Action menu dialog box as shown in the fig below, put a Name and what action you want to do:

  • You can Navigate to a form
  • You can initiate a workflow
  • You can also navigate to a URL.

In this example, I am trying to navigate to a URL (https://www.enjoysharepoint.com). Click on OK.

Add Custom Actions to List Item Menu in SharePoint using SharePoint Designer
sharepoint designer 2013 custom actions

Now Save the page, the menu will appear like below:

Add custom actions to list item menu sharepoint 2013
sharepoint user custom actions

And when you click on that menu, you will be navigated to EnjoySharePoint.com

Add custom action button in List ribbon using SharePoint designer 2013

Now, let us see, how to add a custom action button using sharepoint designer 2013 into SharePoint 2013 list ribbon.

Also, we will see how to navigate to an URL, on click on the custom action button in SharePoint. I will also show how to get the selected item id, on click of the ribbon action button using SharePoint designer 2013.

We will also see how to call a JavaScript function, on click on a custom ribbon action button in SharePoint 2013/2016/Online.

The same way we can add a custom action button using designer in SharePoint 2013/2016/Online.

Add custom action button SharePoint designer

Follow below steps to add custom buttons to SharePoint list ribbon using SharePoint designer 2013

Open your SharePoint 2013 site using SharePoint designer 2013, then from the Site objects click on the Lists and Libraries from the navigation.

This will display all the lists and libraries in the page. Click on the particular list in which you want to add the button. Then from the List settings page, go to the ribbon click on Custom Action -> View Ribbon as shown in the fig below:

add custom action button sharepoint designer
Add custom action button in List ribbon using SharePoint designer 2013

This will open the Create Custom Action dialog box, Give a Name for the button and optionally put a description. Then in the Select the type of action there are three options to do:

  • Navigate to form: You can give the form name where you want to navigate.
  • Initiate workflow: You can initiate any workflow associated with the list by choosing this option.
  • Navigate to URL: You can specify the URL where you want to navigate on click on that button.

Here first we will choose to Navigate to URL option and give the URL like below:

Add custom action button in List ribbon using SharePoint designer 2013
Add custom action button in SharePoint List ribbon using SharePoint designer 2013

Then in the Advanced custom action options, you can provide the Button image URLs and then in the Ribbon Location, you can provide the where the button will appear in the Ribbon. Here I have given the default option “Ribbon.ListItem.Actions.Controls._children“.

In this case, the button will appear in the list ribbon under the Items tab in the Actions section. see fig below:

how to add custom ribbon action on list/libraries in sharepoint 2013
sharepoint user custom action javascript

You can check out SharePoint 2013 Ribbon Locations in this MSDN article.

Now once you click on OK in the Create Custom Action dialog box, then open the list in the browser, you will be able to see the button below. Once you will click on the button you will be redirected to the provided URL presented in the Custom Action dialog box.

sharepoint custom action javascript
sharepoint user custom action scriptlink

Open JavaScript Dialog box on custom action button click

You can open a JavaScript dialog box by writing the below line in the Navigate to URL in the Select the type of action:

javascript: alert('Hello World !!!');
sharepoint custom action ribbon location
sharepoint 2013 custom actions

You can also call any JavaScript function presented on the page. You can put the below code in a script editor web part in the List view page.

<script type="text/javascript">
function CallHello() {
alert ('Hello World !!!');
}
</script>

Then you can modify the Navigate to URL and can write like below:

javascript: CallHello();
command action sharepoint ribbon
sharepoint 2013 custom action javascript

Get Selected Item Ids on custom action button click

We can also get Ids of the selected items by using the below JavaScript code. Edit the page and then add a script editor web part into the page. Then insert the below JavaScript code:

<script type="text/javascript">
function GetItemId() {
var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var selectedItems = ";
for (index in items) {
alert (items[index].id);
}
}
</script>

Now modify the Navigate to URL option like below in the Create Custom Action dialog box.

javascript: GetItemId();

Now whenever the user selects one or more than one list item and then click on the custom ribbon button which we have just created, it will display the selected item ids in SharePoint.

Add user custom action to list ECB menu in SharePoint Online using JavaScript object model (jsom)

Now, let us see, how we can add a custom action to list the ECB menu in SharePoint Online using the JavaScript object model. In my previous post, we have discussed on 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, which you can read from here.

Add user custom action to list ECB menu in SharePoint Online using JavaScript object model

Here also you can use the below code inside a script editor web part in web part page in SharePoint 2013.

<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 ECB Menu" />
<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 oList = web.get_lists().getByTitle('MeetingAnnouncement');
var customActions = oList.get_userCustomActions();

var newCustomActionMenu = customActions.add();
newCustomActionMenu.set_location('EditControlBlock');
newCustomActionMenu.set_sequence(200);
newCustomActionMenu.set_title('EnjoySharePoint.com');
newCustomActionMenu.set_url('https://www.enjoysharepoint.com');
newCustomActionMenu.update();
clientContext.load(oList, 'Title' ,'UserCustomActions');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
Function.createDelegate(this, this.onFailure));
}
function onSuccess() {
alert('New Item Added to ECB Menu');
}
function onFailure(sender, args) {
alert('Error Occurred. ' + args.get_message());
}
</script>

Once you execute the code, you can see the option will appear in the ECB menu like below:

Add user custom action to SharePoint Online jsom
Add user custom action to SharePoint Online jsom

Here we saw, how to add user custom action to list ECB menu in SharePoint Online using JavaScript object model (jsom).

Add/Remove User Custom Actions (Site Actions Menu) Programmatically using JSOM in SharePoint Online

Now let us see, how to add user custom actions (site actions menu) programmatically using JSOM (JavaScript Object Model) in SharePoint Online Office 365. We will also check, how to remove user custom actions (site actions menu) programmatically using JSOM (JavaScript Object Model) in SharePoint Online.

We will also see, how to remove UserCustomActions from Ribbon in the SharePoint Online list using csom?

The links will be added to the SharePoint site actions menu in SharePoint Online Office 365 using the JavaScript object model.

Add User Custom Actions (Site Actions Menu) Programmatically using JSOM in SharePoint Online

Below is the jsom code to add an item to the site actions menu in SharePoint Online Office 365 using the JavaScript Object Model (jsom). We can add the below code inside a script editor web part which we can put inside a SharePoint web part page.

Below is the full code to add user custom actions (site actions menu) programmatically using javascript.

<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">
$(document).ready(function() {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', AddCustomMenuAction);
});

function AddCustomMenuAction() {
var clientContext = new SP.ClientContext();
var oWeb = clientContext.get_web();
var menuActions = oWeb.get_userCustomActions();
var menuAction = menuActions.add();
menuAction.set_location('Microsoft.SharePoint.StandardMenu');
menuAction.set_sequence(101);
menuAction.set_group('SiteActions');
menuAction.set_title("Go to EnjoySharePoint");
menuAction.set_url("https://www.enjoysharepoint.com/");
menuAction.update();
clientContext.load(menuActions);
clientContext.executeQueryAsync(OnSuccess, OnFailure);
}

function OnSuccess() {
alert('Custom menu action added in site actions');
}

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

Once we add the below code then we can see the menu options like below:

Add User Custom Actions (Site Actions Menu) Programmatically using JSOM in SharePoint Online
Add User Custom Actions (Site Actions Menu) Programmatically using JSOM in SharePoint Online

Remove User Custom Actions (Site Actions Menu) Programmatically using JSOM in SharePoint Online

Now, we will see how to remove user custom actions (Site actions menu) programmatically using the javascript object model in SharePoint Online Office 365.

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

Remove User Custom Actions (Site Actions Menu) Programmatically using JSOM in SharePoint Online
Remove User Custom Actions (Site Actions Menu) Programmatically using JSOM in SharePoint Online

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

Below is the full code to remove user custom actions in SharePoint using jsom.

<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.

add User Custom Actions Programmatically using JSOM in SharePoint Online
add user custom action sharepoint

Remove UserCustomActions from Ribbon in SharePoint online list using csom

Here we will see, how to remove UserCustomActions from Ribbon, FormRibbon, and ECB Menu using csom .Net managed object model code in SharePoint Online. We will use here C#.Net managed object model code where we will use below dlls:

  • Microsoft.SharePoint.Client.Dll
  • Microsoft.SharePoint.Client.Runtime.Dll

Here I have a list where we have added UserCustomActions buttons to Ribbon, FormRibbon and to ECB menu. For one of our requirements, we need to remove the ribbon buttons. So I wrote a console application by using .Net managed object model code.

Here we are retrieving the user custom actions for the list by using the below code:

var userCustomActions = list.UserCustomActions;

Then we are calling the DeleteCustomAction method which will check the particular custom action name and then delete it.

public static void DeleteCustomRibbonActionFromList()
{
using (ClientContext ctx = new ClientContext("https://onlysharepoint2013.sharepoint.com/sites/Bhawana/"))
{
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = new SharePointOnlineCredentials(GetSPOAccountName(), GetSPOSecureStringPassword());
List list = ctx.Web.Lists.GetByTitle("MyTestList");
ctx.Load(list);
ctx.ExecuteQuery();
var userCustomActions = list.UserCustomActions;
ctx.Load(userCustomActions);
ctx.ExecuteQuery();
DeleteCustomAction(userCustomActions, "RibbonDocumentApproval", ctx);
DeleteCustomAction(userCustomActions, "FormRibbonDocumentApproval", ctx);
DeleteCustomAction(userCustomActions, "ECBDocumentApproval", ctx);
}
}

private static void DeleteCustomAction(UserCustomActionCollection userCustomActions, string customActionName, ClientContext ctx)
{
for (int i = userCustomActions.Count – 1; i >= 0; i–)
{
if (userCustomActions[i].Name == customActionName)
{
userCustomActions[i].DeleteObject();
ctx.ExecuteQuery();
}
}
}

private static string GetSPOAccountName()
{
try
{
return ConfigurationManager.AppSettings["SPOAccount"];
}
catch
{
throw;
}
}

private static SecureString GetSPOSecureStringPassword()
{
try
{
var secureString = new SecureString();
foreach (char c in ConfigurationManager.AppSettings["SPOPassword"])
{
secureString.AppendChar(c);
}
return secureString;
}

catch
{
throw;
}
}

It will remove the user custom actions from Ribbon in SharePoint online list using csom.

Here, we learned how to add user custom actions (site actions menu) programmatically using JSOM (JavaScript Object Model) in SharePoint Online Office 365.

We will also check, how to remove user custom actions (site actions menu) programmatically using JSOM (JavaScript Object Model) in SharePoint Online.

Also, we saw how to remove UserCustomActions from Ribbon in the SharePoint Online list using csom?

Add Custom Actions to List Item Menu in SharePoint 2010 using SharePoint Designer 2010

Now, we will see how to add a custom action to a list item menu using SharePoint designer 2010 in SharePoint 2010.

Follow the below steps to add a custom action to list item in SharePoint:

Open SharePoint Designer 2010 and navigate to list from site objects for which you want to add the custom action as shown in the fig below.

Add custom actions to list item menu sharepoint 2010
Add Custom Actions to List Item Menu in SharePoint

Then go to the Custom Action section from the list settings page and click on New as shown in the figure below:

how to add custom actions to list item menu sharepoint 2010
Add Custom Actions to List Item Menu in SharePoint 2010

This will open the “Create Custom Action” dialog box. Here give the Name, Description, Select the type of action. SharePoint provides 3 types of activities that you can do:

  • Navigate to a form for this list
  • Initiate workflow
  • Navigate to URL

Here we will choose to Navigate to URL and from the Browser button you can select any URL, Here we have selected a Document library URL.

Then scroll down in the dialog box and give a sequence number, Anything over 10000 is a good practice, so you do not interfere with any other items in the list. Check the fig below:

how to add custom actions to list item menu sharepoint 2010 using designer
Add Custom Actions to List Item Menu in SharePoint 2013

Then click OK, and you now have a custom action, associated with a list item. When you open the list and see the custom context menu, the custom action will appear like below:

Add custom actions to list item menu sharepoint designer 2010
Add Custom Actions to List Item Menu in SharePoint online

We learned how to add a custom menu in the ECB list item menu using SharePoint 2013/2010 designer in SharePoint 2013/2010.

You may like the following SharePoint tutorials:

In this tutorial, we learned about SharePoint user custom actions.

>