{"id":4092,"date":"2021-02-16T10:25:17","date_gmt":"2021-02-16T10:25:17","guid":{"rendered":"https:\/\/himbap.com\/blog\/?p=4092"},"modified":"2021-02-16T10:25:17","modified_gmt":"2021-02-16T10:25:17","slug":"add-flyout-and-identify-selected-option-dynamics-365-ce","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=4092","title":{"rendered":"Add Flyout and identify Selected Option &#8211; Dynamics 365 CE"},"content":{"rendered":"<p>Requirement<br \/>\nAdd a custom Flyout menu with buttons and identify which button is clicked.<\/p>\n<p>Solution<br \/>\nSometimes we need to add a custom flyout ribbon button and need to write code depending on the button which is clicked. Normally that is done using menu, but I will be adding button to flyout and using command there to perform action. I will be using Ribbon workbench solution to customize ribbon button which you can download from https:\/\/www.develop1.net\/public\/rwb\/ribbonworkbench.aspx or can use from XrmToolBox.<\/p>\n<p>Let see how we can do that.<\/p>\n<p>1. Setup a custom solution and add your entity (just add metadata nothing else)<br \/>\n2. Create a java script web resource with following code<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nif (typeof (HIMBAP) == &quot;undefined&quot;) {\r\n    var HIMBAP = { __namespace: true };\r\n}\r\n\r\n\r\nHIMBAP.AccountRibbonLibrary =\r\n    {\r\n       IdentifyFlyoutClick: function (commandProperties)\r\n       {\r\n          if (commandProperties.SourceControlId.includes(&quot;Test1.Button&quot;)) {\r\n                alert(&quot;Test 1 Clicked&quot;);\r\n            }\r\n            else if (commandProperties.SourceControlId.includes(&quot;Test2.Button&quot;))\r\n             {\r\n               alert(&quot;Test 2 Clicked&quot;);\r\n             }\r\n       }\r\n    };\r\n<\/pre>\n<p>In above code I am using <strong>CommandProperties <\/strong>, we will be passing this parameter from the Flyout button command and it will help us to identify which flyout button is selected, it provides these properties<br \/>\n<strong>SourceControlId <\/strong>: The Id value of the Ribbon control that initiated the event.<\/p>\n<p><strong>CommandValueId <\/strong>: A string that is sent with the command event when a button is clicked.<\/p>\n<p><strong>MenuItemId<\/strong>: A reference from a control to the Id of a menu item.<\/p>\n<p>I am checking if button Id contains specific text (<strong>Note<\/strong>: We need to include this in our button Ids)<br \/>\n3. Open Ribbon Workbench solution and select your custom solution which include your entity and web resource, we are using Account entity for the demo.<br \/>\n4. Drag Flyout button and drop it on the Form area.<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4094 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton1-281x300.png\" alt=\"flyoutbutton1\" width=\"281\" height=\"300\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton1-281x300.png 281w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton1-624x667.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton1.png 804w\" sizes=\"(max-width: 281px) 100vw, 281px\" \/><\/a><br \/>\n5. Click on + under Command to add new command, change command Id accordingly and add a Custom JavaScript action<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4095 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton2-300x126.png\" alt=\"flyoutbutton2\" width=\"300\" height=\"126\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton2-300x126.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton2-624x261.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton2.png 778w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n6. Select your web resource, provide function name. Click on the Add Parameter button and select Crm Parameter.<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4096 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton3-300x81.png\" alt=\"flyoutbutton3\" width=\"300\" height=\"81\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton3-300x81.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton3-1024x276.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton3-624x168.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton3.png 1052w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n7. Select CommandProperties from available parameter list<br \/>\n8. Now Drag Menu Selection under the flyout (above the line visible in the flyout button)<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton4.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4097 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton4-300x280.png\" alt=\"flyoutbutton4\" width=\"300\" height=\"280\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton4-300x280.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton4-624x582.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton4.png 635w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n9. Add Buttons under Menu Selection (I have added two buttons)<br \/>\n10. Setup button properties like below (Use command we created in earlier step)<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton5.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4098 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton5-300x173.png\" alt=\"flyoutbutton5\" width=\"300\" height=\"173\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton5-300x173.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton5-1024x590.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton5-624x360.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton5.png 1093w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Make sure you are adding button Ids based on your check for example, I have modified button Id to include the text I am validation in my web resource.<\/p>\n<p>Now Publish your changes and you should be able to see flyout like below and when clicked you should see message based on the selection.<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton6.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4099 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton6-300x223.png\" alt=\"flyoutbutton6\" width=\"300\" height=\"223\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton6-300x223.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton6-624x464.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2021\/02\/flyoutbutton6.png 696w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Summary<\/strong><br \/>\nThis how we can also use command buttons under flyout and can identify which button is clicked. We can further write script to perform different action based on the selection. <\/p>\n<p>Hope it will help someone!<br \/>\n<strong>Keep learning, Keep sharing !!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Requirement Add a custom Flyout menu with buttons and identify which button is clicked. Solution Sometimes we need to add a custom flyout ribbon button and need to write code depending on the button which is clicked. Normally that is done using menu, but I will be adding button to flyout and using command there to perform action. I will&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=4092\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":4102,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,402,522],"tags":[862,860,861,863,859,865,864],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4092"}],"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=4092"}],"version-history":[{"count":7,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4092\/revisions"}],"predecessor-version":[{"id":4106,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4092\/revisions\/4106"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/4102"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}