{"id":24,"date":"2009-06-30T12:02:11","date_gmt":"2009-06-30T12:02:11","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=24"},"modified":"2009-06-30T12:02:11","modified_gmt":"2009-06-30T12:02:11","slug":"hide-custom-button-through-js","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=24","title":{"rendered":"Hide Custom button through JS"},"content":{"rendered":"<p>Today i got requirement to hide my custom button, i \u00a0just picked it&#8217;s id\u00a0with the help of\u00a0IE developer toolbar and used easiest line to hide any control<\/p>\n<p>document.getElementById(&#8216;ISV_New_13_ServiceActivity&#8217;).style.display=&#8217;none&#8217;;<\/p>\n<p>and just publised my entity and started testing it but soon after that i started rubbing my head\u00a0 :-\/\u00a0 as i got JS error, then i test it using alert and found null when tried to get id through document.getElementById.<\/p>\n<p>After some googling i came to know in case of custom button CRM\u00a0behaves differently, maybe it generate\u00a0id at run time, so no way to just use simple line to hide button, so i started to searching id of every IL and comparing it with title of my button and it worked<\/p>\n<p><span style=\"font-size:x-small;color:#0000ff;\"><span style=\"font-size:x-small;color:#0000ff;\"><font size=\"2\" color=\"#0000ff\"><font size=\"2\" color=\"#0000ff\">var<\/p>\n<p><\/font><\/font><\/span><font size=\"2\" color=\"#0000ff\">\u00a0<\/p>\n<p><\/font><\/span><span style=\"font-size:x-small;\">ItemList = document.getElementById(<\/span><span style=\"font-size:x-small;color:#a31515;\"><span style=\"font-size:x-small;color:#a31515;\">&#8220;mnuBar1&#8221;<\/span><\/span><span style=\"font-size:x-small;\">).rows[0].cells[0].getElementsByTagName(<\/span><span style=\"font-size:x-small;color:#a31515;\"><span style=\"font-size:x-small;color:#a31515;\">&#8220;UL&#8221;<\/span><\/span><span style=\"font-size:x-small;\">)[0].getElementsByTagName(<\/span><span style=\"font-size:x-small;color:#a31515;\"><span style=\"font-size:x-small;color:#a31515;\">&#8220;LI&#8221;<\/span><\/span><span style=\"font-size:x-small;\">);<\/span><\/p>\n<p><span style=\"font-size:x-small;color:#0000ff;\"><span style=\"font-size:x-small;color:#0000ff;\">for<\/span><\/span><span style=\"font-size:x-small;\">(<\/span><span style=\"font-size:x-small;color:#0000ff;\"><span style=\"font-size:x-small;color:#0000ff;\">var<\/span><\/span><span style=\"font-size:x-small;\"> i=0; i&lt;ItemList.length-1; i++)<\/span><\/p>\n<p><span style=\"font-size:x-small;color:#0000ff;\"><span style=\"font-size:x-small;color:#0000ff;\">{var<\/span><\/span><span style=\"font-size:x-small;\"> str=ItemList[i].id;<\/span><\/p>\n<p><span style=\"font-size:x-small;color:#0000ff;\"><span style=\"font-size:x-small;color:#0000ff;\">if<\/span><\/span><span style=\"font-size:x-small;\">(str.match(<\/span><span style=\"font-size:x-small;color:#a31515;\"><span style=\"font-size:x-small;color:#a31515;\">&#8216;ServiceActivity&#8217;<\/span><\/span><span style=\"font-size:x-small;\">))<\/span><\/p>\n<p><span style=\"font-size:x-small;\">{<\/span><span style=\"font-size:x-small;color:#0000ff;\"><span style=\"font-size:x-small;color:#0000ff;\">Item<span style=\"font-size:x-small;color:#0000ff;\"><span style=\"font-size:x-small;color:#0000ff;\">List<\/span><\/span>[i].style.display = &#8220;none&#8221;;<br \/>\nbreak<\/span><\/span><span style=\"font-size:x-small;\">;<\/span><span style=\"font-size:x-small;\">}}<\/span><\/p>\n<p><span style=\"font-size:x-small;\">Hope it will help somebody&#8230;&#8230;..<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today i got requirement to hide my custom button, i \u00a0just picked it&#8217;s id\u00a0with the help of\u00a0IE developer toolbar and used easiest line to hide any control document.getElementById(&#8216;ISV_New_13_ServiceActivity&#8217;).style.display=&#8217;none&#8217;; and just publised my entity and started testing it but soon after that i started rubbing my head\u00a0 :-\/\u00a0 as i got JS error, then i test it using alert and found&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=24\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[25],"tags":[],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/24"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24"}],"version-history":[{"count":0,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/24\/revisions"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}