{"id":1486,"date":"2015-04-07T07:05:50","date_gmt":"2015-04-07T07:05:50","guid":{"rendered":"https:\/\/mahenderpal.wordpress.com\/?p=1486"},"modified":"2015-11-30T10:40:37","modified_gmt":"2015-11-30T10:40:37","slug":"overriding-out-of-box-command-button-behavior-step-by-step","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=1486","title":{"rendered":"Overriding out of box command button behavior &#8211; Step by Step"},"content":{"rendered":"<p>Did you get a requirement to override a system ribbon or command button?? If yes then this blog post going to help you to implement your requirement.<\/p>\n<p><strong>Requirement<\/strong>: Let\u2019s say we have requirement to prompt user before saving the record and based on select we need to save or cancel save operation.<\/p>\n<p><strong>Solution<\/strong>: We can create a custom button to replicate out of the box button, we will be calling same method that is called on out of box button. Once our button is ready we will hide out of box button. To implement our requirement use\u00a0following steps<\/p>\n<ul>\n<li>Download and install <strong>RibbonWorkBench<\/strong> solution<\/li>\n<li>Create a <strong>Demo<\/strong> solution and add account entity to our solution.<\/li>\n<\/ul>\n<p><strong>Note<\/strong>: You can follow our <a href=\"https:\/\/himbap.com\/blog\/?p=1473\">previous post<\/a> to get <strong>RibbonWorkBench<\/strong> solution, to create demo solution and adding existing entities. We are going to override <strong>Save<\/strong> button on account entity<\/p>\n<p>Open Demo solution and add new web resource by navigating <strong>Components -&gt;Web Resources -&gt; New<\/strong><\/p>\n<ul>\n<li>Fill below properties and click on <strong>Text Editor<\/strong> button\n<ul>\n<li><strong>Name<\/strong>: OnSave.js<\/li>\n<li><strong>Display Name<\/strong>: OnSave.js<\/li>\n<li><strong>Type<\/strong>: Script (Jscript)<\/li>\n<\/ul>\n<\/li>\n<li>At this point create a blank function like below<\/li>\n<\/ul>\n<p>function OverrideSave()<\/p>\n<p>{\u00a0\u00a0 \/\/We will be changing it in later step\u00a0\u00a0 }<\/p>\n<ul>\n<li><strong>Save<\/strong> and <strong>Publish<\/strong> web resource<\/li>\n<\/ul>\n<p>Now we will create a custom button and will copy properties or save button. Using following steps:<\/p>\n<ul>\n<li>Open <strong>RibbonWorkBench<\/strong> and select our <strong>Demo<\/strong> solution<\/li>\n<li>Drag Button from <strong>Toolbox<\/strong> and leave it next to <strong>Save <\/strong>under Form section<\/li>\n<li>Right click on system <strong>Save<\/strong> button and select <strong>Customize Command<\/strong><\/li>\n<li>Use same properties of system Save button to our custom button except <strong>Sequence<\/strong> and <strong>CommandCore<\/strong> properties (we need to\u00a0copy and paste these properties one by one)<a href=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/04\/savebuttons.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1487 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/04\/savebuttons.png?w=300\" alt=\"SaveButtons\" width=\"300\" height=\"148\" \/><\/a><\/li>\n<\/ul>\n<p>Now we need to check command which is associated with system save button and need to see which function and parameter used for that. Follow below steps<\/p>\n<ul>\n<li>Select <strong>Mscrm<\/strong>.<strong>SavePrimary <\/strong>under Commands and click on<strong> Actions <\/strong>lookup to check for<strong> function name and parameter, <\/strong>we got this command name from <strong>Save<\/strong> button <strong>commandcore<\/strong> property<\/li>\n<\/ul>\n<p><a href=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/04\/systembutton.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1488 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/04\/systembutton.jpg?w=300\" alt=\"systembutton\" width=\"300\" height=\"82\" \/><\/a><\/p>\n<ul>\n<li>Right click on <strong>Command<\/strong> and select <strong>Add New<\/strong>, we need to add command for your custom <strong>Save <\/strong>button<\/li>\n<li>Click on <strong>Actions<\/strong> lookup -&gt; click on <strong>Add<\/strong> and select <strong>JavaScript Function Action<\/strong><\/li>\n<li>Write our function name and select our web resource.<\/li>\n<li>Click on <strong>Parameters<\/strong> lookup-&gt;click on <strong>Add<\/strong> and select <strong>Crm Parameter<\/strong><\/li>\n<li>Select <strong>Primary Control<\/strong> under <strong>Value<\/strong> drop down<\/li>\n<li>It should look like below<\/li>\n<\/ul>\n<p><a href=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/04\/override.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1489 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/04\/override.jpg?w=300\" alt=\"override\" width=\"300\" height=\"59\" \/><\/a><\/p>\n<ul>\n<li>Select our custom <strong>Save<\/strong> button and select our command name under <strong>command<\/strong> drop down<\/li>\n<li>Right click on system <strong>Save<\/strong> button and select <strong>Hide Button<\/strong> option<\/li>\n<li>Click on <strong>Publish<\/strong> button to publish your changes.<\/li>\n<li>Open our java script web resource and change function definition like below<\/li>\n<\/ul>\n<p>function OverrideSave()<\/p>\n<p>{\/\/Capture response<\/p>\n<p>var response=confirm(&#8220;Do want to save ??&#8221;);<\/p>\n<p>if(response==true){<\/p>\n<p>\/\/system function<\/p>\n<p>Mscrm.RibbonActions.saveForm();<\/p>\n<p>} }<\/p>\n<ul>\n<li><strong>Save<\/strong> and <strong>Publish<\/strong> web resource and open any account record.<\/li>\n<li>Chang some field value and click on Save button you should get prompt like below<\/li>\n<\/ul>\n<p><a href=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/04\/prompt.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1490 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2015\/04\/prompt.jpg?w=300\" alt=\"prompt\" width=\"300\" height=\"195\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you get a requirement to override a system ribbon or command button?? If yes then this blog post going to help you to implement your requirement. Requirement: Let\u2019s say we have requirement to prompt user before saving the record and based on select we need to save or cancel save operation. Solution: We can create a custom button to&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=1486\">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":[8],"tags":[47,126,143,144],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1486"}],"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=1486"}],"version-history":[{"count":3,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1486\/revisions"}],"predecessor-version":[{"id":1907,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1486\/revisions\/1907"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}