{"id":6827,"date":"2021-07-01T09:14:45","date_gmt":"2021-07-01T09:14:45","guid":{"rendered":"https:\/\/softreetechnology.com\/?p=6827"},"modified":"2021-07-01T09:48:43","modified_gmt":"2021-07-01T09:48:43","slug":"add-modify-and-delete-user-custom-action-for-list-or-library-item","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/","title":{"rendered":"Add, Modify And Delete User Custom Action For List Or Library Item"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>IT and business users commonly use the custom action. In this article, I have created a tool that can add features to SharePoint through a distinctive design interface with ribbon controls.<\/p>\n\n\n\n<p>Here we have created 4 buttons for the custom action operations for the list and site.<\/p>\n\n\n\n<p><strong>Button 1 &#8211;&nbsp;Create User Custom Action for list<\/strong><\/p>\n\n\n\n<p>This button calls the function \u2018<strong>createUserCustomActionList ()\u2019<\/strong>, in this function, we are retrieving the list in which we want to add the custom action. Then get the custom action collections by using \u2018<strong>get_userCustomActions()\u2019<\/strong> and add the new custom action and set the properties and update it.<strong> (Here we have set the title as \u2018My First User Custom Action\u2019).<\/strong><\/p>\n\n\n\n<p><strong>Button 2 &#8211; Delete User CustomAction for list<\/strong><\/p>\n\n\n\n<p>This button calls the function \u2018<strong>deleteUserCustomAction()<\/strong>\u2019, in this function,&nbsp;we are retrieving all the list custom action collection. Then get the user custom action by its name and delete it by using \u2018<strong>deleteObject()<\/strong>\u2019.<\/p>\n\n\n\n<p><strong>Button 3 &#8211; Modify User CustomAction for list<\/strong><\/p>\n\n\n\n<p>This button calls the function<strong> \u2018<\/strong><strong>modifyUserCustomAction()\u2019,&nbsp;<\/strong>in this function,&nbsp;we are retrieving all the list custom action collection. Then get the user custom action by its name and set the title or you can also set the properties which you want to modify, here we are modifying the title of the custom action by <strong>\u2018Custom action\u2019.<\/strong><\/p>\n\n\n\n<p><strong>Button 4 &#8211; Create User CustomAction for Site<\/strong><\/p>\n\n\n\n<p>This button calls the function \u2018<strong>createUserCustomActionSite()\u2019<\/strong>, in this function,&nbsp;we are retrieving the web. Then get the site custom action collections by using \u2018<strong>get_userCustomActions()\u2019<\/strong> and add the new custom action in the site and set the properties and update it.<strong> (Here we have set the title as \u2018Website User Custom Action\u2019).<\/strong><\/p>\n\n\n\n<p>Follow the below code snippet,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script type = \"text\/javascript\" language = \"javascript\"&gt;\nfunction createUserCustomActionList() {\n    var ctx = new SP.ClientContext.get_current();\n    var web = ctx.get_web();\n    var list = web.get_lists().getByTitle('My List');\n    var CustomActionColl = list.get_userCustomActions();\n    var custAction = CustomActionColl.add();\n    custAction.set_location('EditControlBlock');\n    custAction.set_sequence(100);\n    custAction.set_title('My First User Custom Action');\n    custAction.update();\n    ctx.load(list, 'Title', 'UserCustomActions');\n    ctx.executeQueryAsync(function() {\n        alert('Custom action created successfully for ' + list.get_title());\n    }, function(s, a) {\n        alert('Request failed. ' + a.get_message());\n    });\n}\n\nfunction createUserCustomActionSite() {\n    var ctx = new SP.ClientContext.get_current();\n    var web = ctx.get_web();\n    var CustomActionColl = web.get_userCustomActions();\n    var custAction = CustomActionColl.add();\n    custAction.set_location('Microsoft.SharePoint.StandardMenu');\n    custAction.set_group('SiteActions');\n    custAction.set_sequence(101);\n    custAction.set_title('Website User Custom Action');\n    custAction.set_description('Description for custom action.');\n    custAction.update();\n    ctx.load(web, 'Title', 'UserCustomActions');\n    ctx.executeQueryAsync(function() {\n        alert('Custom action created successfully for ' + web.get_title());\n    }, function(sender, args) {\n        alert('Error ' + args.get_message());\n    });\n}\nFunction modifyUserCustomAction() {\n    var ctx = new SP.ClientContext.get_current();\n    var web = ctx.get_web();\n    var list = web.get_lists().getByTitle('My List');\n    var CustomActionColl = list.get_userCustomActions();\n    ctx.load(list, 'UserCustomActions', 'Title');\n    ctx.executeQueryAsync(function() {\n        var customActionEnum = CustomActionColl.getEnumerator();\n        while (customActionEnum.moveNext()) {\n            var custAction = customActionEnum.get_current();\n            if (custAction.get_title() == 'My First User Custom Action') {\n                custAction.set_title('Custom action');\n                custAction.update();\n                ctx.load(custAction);\n                ctx.executeQueryAsync(function() {\n                    alert('Custom action modified successfully for ' + list.get_title());\n                }, function(a, s) {\n                    alert('Error ' + a.get_message());\n                });\n            }\n        }\n    }, function(a, s) {\n        alert('Error ' + a.get_message());\n    });\n}\n\nfunction deleteUserCustomAction() {\n    var ctx = new SP.ClientContext.get_current();\n    var web = ctx.get_web();\n    var list = web.get_lists().getByTitle('My List');\n    var CustomActionColl = list.get_userCustomActions();\n    ctx.load(list, 'UserCustomActions', 'Title');\n    ctx.executeQueryAsync(function() {\n        var customActionEnum = CustomActionColl.getEnumerator();\n        while (customActionEnum.moveNext()) {\n            var custAction = customActionEnum.get_current();\n            if (custAction.get_title() == 'My First User Custom Action') {\n                custAction.deleteObject();\n                ctx.load(custAction);\n                ctx.executeQueryAsync(function() {\n                    alert('Custom action deleted successfully for ' + list.get_title());\n                }, function(s, a) {\n                    alert('Error ' + a.get_message());\n                });\n            }\n        }\n    }, function(a, s) {\n        alert('Error ' + a.get_message());\n    });\n}\n&lt;\/script&gt;\n &lt;input type=\"button\" value=\"Create User CustomAction for list\" id=\"create\" onclick=\"createUserCustomActionList()\" \/&gt;\n&lt;\/br &gt;\n&lt;\/br &gt;\n    &lt;input type=\"button\" value=\"Delete User CustomAction for list\" id=\"Delete\" onclick=\"deleteUserCustomAction()\" \/&gt;\n&lt;\/br &gt;\n    &lt;\/br &gt;\n        &lt;input type=\"button\" value=\"Modify User CustomAction for list\" id=\"Delete\" onclick=\"modifyUserCustomAction()\" \/&gt;\n&lt;\/br &gt;\n     &lt;\/br &gt;\n         &lt;input type=\"button\" value=\"Create User CustomAction for site\" id=\"Delete\" onclick=\"createUserCustomActionSite()\" \/&gt;\n&lt;\/br &gt;<\/code><\/pre>\n\n\n\n<p>JavaScript<\/p>\n\n\n\n<p><strong>Button 1 &#8211;&nbsp;<\/strong><strong>Create User CustomAction for list<\/strong><\/p>\n\n\n\n<p>Click on the button.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son1.png\" alt=\"Add, Modify and Delete User custom action for list or library item\"\/><\/figure>\n\n\n\n<p>In the below screenshot you can see the alert-success message. Click on <strong>ok.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son2.png\" alt=\"Add, Modify and Delete User custom action for list or library item\"\/><\/figure>\n\n\n\n<p>In the below screenshot, you can see the custom action is added successfully.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son3.png\" alt=\"Add, Modify and Delete User custom action for list or library item\"\/><\/figure>\n\n\n\n<p><strong>Button 2 &#8211; Delete User CustomAction for list<\/strong><\/p>\n\n\n\n<p>Click on the button. You can see the alert-success message, click on<strong>&nbsp;OK.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son4.png\" alt=\"Add, Modify and Delete User custom action for list or library item\"\/><\/figure>\n\n\n\n<p>You can see in the screenshot custom action is deleted successfully.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son5.png\" alt=\"Add, Modify and Delete User custom action for list or library item\"\/><\/figure>\n\n\n\n<p><strong>Button 3 &#8211; Modify User CustomAction for list<\/strong><\/p>\n\n\n\n<p>Click on the button. You can see the alert-success message, click on <strong>OK.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son6.png\" alt=\"Add, Modify and Delete User custom action for list or library item\"\/><\/figure>\n\n\n\n<p>You can see in the below screenshot custom action name is change into \u2018Custom action\u2019.<br><img decoding=\"async\" alt=\"Add, Modify and Delete User custom action for list or library item\" class=\"\" src=\"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son7.png\"><\/p>\n\n\n\n<p><strong>Button 4 &#8211; Create User CustomAction for Site<\/strong><\/p>\n\n\n\n<p>Click on the button. You can see the alert-success message, click on<strong> ok.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son8.png\" alt=\"Add, Modify and Delete User custom action for list or library item\"\/><\/figure>\n\n\n\n<p>In the below screenshot you can see the custom action is successfully added to the site.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son9.png\" alt=\"Add, Modify and Delete User custom action for list or library item\"\/><\/figure>\n\n\n\n<p>Key Words:<br><\/p>\n\n\n\n<p>1.Add, Update and Remove user custom action for site, list or library items using JSOM.<br>2.How to add, modify and delete custom action for site, list or library items using JSOM.<br>3.How to add, remove, update user custom action for site, list or library menu using JSOM.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction IT and business users commonly use the custom action. In this article, I have created a tool that can add features to SharePoint through a distinctive design interface with ribbon controls. Here we have created 4 buttons for the custom action operations for the list and site. Button 1 &#8211;&nbsp;Create User Custom Action for list This button calls the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-6827","post","type-post","status-publish","format-standard","hentry","category-sharepoint"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Add, Modify And Delete User Custom Action For List Or Library Item - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add, Modify And Delete User Custom Action For List Or Library Item - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"Introduction IT and business users commonly use the custom action. In this article, I have created a tool that can add features to SharePoint through a distinctive design interface with ribbon controls. Here we have created 4 buttons for the custom action operations for the list and site. Button 1 &#8211;&nbsp;Create User Custom Action for list This button calls the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-01T09:14:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-01T09:48:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son1.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Add, Modify And Delete User Custom Action For List Or Library Item - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/","og_locale":"en_US","og_type":"article","og_title":"Add, Modify And Delete User Custom Action For List Or Library Item - Softree Technology","og_description":"Introduction IT and business users commonly use the custom action. In this article, I have created a tool that can add features to SharePoint through a distinctive design interface with ribbon controls. Here we have created 4 buttons for the custom action operations for the list and site. Button 1 &#8211;&nbsp;Create User Custom Action for list This button calls the [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/","og_site_name":"Softree Technology","article_published_time":"2021-07-01T09:14:45+00:00","article_modified_time":"2021-07-01T09:48:43+00:00","og_image":[{"url":"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son1.png","type":"","width":"","height":""}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Add, Modify And Delete User Custom Action For List Or Library Item","datePublished":"2021-07-01T09:14:45+00:00","dateModified":"2021-07-01T09:48:43+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/"},"wordCount":488,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/#primaryimage"},"thumbnailUrl":"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son1.png","articleSection":["SharePoint"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/","url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/","name":"Add, Modify And Delete User Custom Action For List Or Library Item - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/#primaryimage"},"thumbnailUrl":"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son1.png","datePublished":"2021-07-01T09:14:45+00:00","dateModified":"2021-07-01T09:48:43+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/#primaryimage","url":"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son1.png","contentUrl":"https:\/\/csharpcorner-mindcrackerinc.netdna-ssl.com\/UploadFile\/BlogImages\/06302021111600AM\/son1.png"},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/add-modify-and-delete-user-custom-action-for-list-or-library-item\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Add, Modify And Delete User Custom Action For List Or Library Item"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=6827"}],"version-history":[{"count":2,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6827\/revisions"}],"predecessor-version":[{"id":6830,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6827\/revisions\/6830"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=6827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=6827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=6827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}