{"id":1383,"date":"2014-06-12T14:52:57","date_gmt":"2014-06-12T12:52:57","guid":{"rendered":"http:\/\/blog.kodono.info\/wordpress\/?p=1383"},"modified":"2014-06-12T14:52:57","modified_gmt":"2014-06-12T12:52:57","slug":"delete-a-user-custom-action-from-sharepoint-javascript","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2014\/06\/12\/delete-a-user-custom-action-from-sharepoint-javascript\/","title":{"rendered":"Delete a User Custom Action from Sharepoint [JavaScript]"},"content":{"rendered":"<p>The MSDN documentation is a nightmare&#8230;. For example Microsoft provides <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/office\/ff408647%28v=office.14%29.aspx\">an example to create a User Custom Action for Sharepoint<\/a>, however there is no code about how to delete it.<\/p>\n<p>So here is the code to use to delete the usercustomaction just created with the above example:<\/p>\n<pre class=\"brush:javascript\">\r\nvar siteUrl = '\/site collection\/site\/';\r\n\r\nfunction deleteUserCustomAction() {\r\n    this.clientContext = new SP.ClientContext(siteUrl);\r\n    var oWebsite = clientContext.get_web();\r\n    this.collUserCustomAction = oWebsite.get_userCustomActions();\r\n    clientContext.load(oWebsite,'UserCustomActions','Title');\r\n    clientContext.executeQueryAsync(Function.createDelegate(this, this.deleteCustomAction), Function.createDelegate(this, this.onQueryFailed));\r\n}\r\nfunction deleteCustomAction() {\r\n    var customActionEnumerator = collUserCustomAction.getEnumerator();\r\n    while (customActionEnumerator.moveNext())  {\r\n      var oUserCustomAction = customActionEnumerator.get_current();\r\n      if (oUserCustomAction.get_title() == 'New Menu Item') {\r\n           oUserCustomAction.deleteObject();        \r\n           clientContext.load(oUserCustomAction);\r\n           clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));\r\n        }\r\n    }\r\n}\r\nfunction onQuerySucceeded() {\r\n    alert('Custom action removed');\r\n}\r\nfunction onQueryFailed(sender, args) {\r\n    alert('Request failed. ' + args.get_message() + '\\n' + args.get_stackTrace());\r\n}\r\ndeleteUserCustomAction()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The MSDN documentation is a nightmare&#8230;. For example Microsoft provides an example to create a User Custom Action for Sharepoint, however there is no code about how to delete it. So here is the code to use to delete the usercustomaction just created with the above example: var siteUrl = &#8216;\/site collection\/site\/&#8217;; function deleteUserCustomAction() { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[13,33],"tags":[24,152,158,117],"class_list":["post-1383","post","type-post","status-publish","format-standard","hentry","category-niveau-intermediaire","category-programmation","tag-javascript","tag-niveau-intermediaire","tag-programmation","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1383"}],"version-history":[{"count":1,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1383\/revisions"}],"predecessor-version":[{"id":1384,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1383\/revisions\/1384"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}