{"id":4334,"date":"2022-09-01T05:23:15","date_gmt":"2022-09-01T05:23:15","guid":{"rendered":"https:\/\/himbap.com\/blog\/?p=4334"},"modified":"2022-09-01T05:44:45","modified_gmt":"2022-09-01T05:44:45","slug":"implementing-prompt-dialog-in-d365-ce-part-2","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=4334","title":{"rendered":"Implementing Prompt dialog in D365 CE Part 2"},"content":{"rendered":"<p><strong>Requirements<\/strong><br \/>\nLet\u2019s say we have requirement where user can put opportunity on hold but before doing he needs to enter comment which should be saved in the opportunity.<\/p>\n<p>In the <a href=\"https:\/\/himbap.com\/blog\/?p=4325\">earlier part <\/a> we discussed of creating prompt and updating opportunity, in this part we will discuss next items.<\/p>\n<p><strong>Details<\/strong><br \/>\nWe have our prompt page ready now we need to create a web resource and need to add below scripts to call the dialog and create required buttons to open this dialog. We will be adding two buttons one to put opportunity on hold and another one to remove opportunity from on hold so let&#8217;s start<\/p>\n<p><strong>Open Dialog Dialog from Button<\/strong><br \/>\nWe need to write script to call our dialog, so we can use following code to open dialog.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction PlaceOnHold(control) {\r\n    var formContext = control;\r\n    var oppId = formContext.data.entity.getId().substring(1, 37);\r\n\r\n    var dialogPage = {\r\n        pageType: &quot;webresource&quot;,\r\n        webresourceName: &quot;him_OnHold.html&quot;,\r\n        data: oppId\r\n    };\r\n    var navigationOptions = {\r\n        target: 2,\r\n        width: 300,\r\n        height: 230,\r\n        position: 1\r\n    };\r\n    Xrm.Navigation.navigateTo(dialogPage , navigationOptions).then(\r\n        function success() {\r\n\r\n        },\r\n        function error(errordetails) {\r\n            console.log(errordetails);\r\n        }\r\n    );\r\n\r\n}\r\n\r\n<\/pre>\n<p>In the above code we are first getting primary control parameter from the button which will help us to get the opportunity id and then we are calling the dialog busing navigateTo method by passing dialog web resource details and the navigation options.<\/p>\n<p>In the same script let&#8217;s add another method to remove opportunity from on hold.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction RemoveOnHold(control) {\r\n    var formContext = control;\r\n    var oppId = formContext.data.entity.getId().substring(1, 37);\r\n    debugger;\r\n    var data =\r\n    {\r\n        &quot;him_placeonhold&quot;: false,\r\n    }\r\n    Xrm.WebApi.updateRecord(&quot;opportunity&quot;, oppId, data).then(\r\n        function success(result) {\r\n          parent.location.reload();\r\n\r\n        },\r\n        function (error) {\r\n            console.log(error);\r\n        }\r\n    );\r\n\r\n}\r\n<\/pre>\n<p>We are using updateRecord method and setting our boolean field to false.<\/p>\n<p><strong>Adding Command buttons<\/strong><br \/>\nWe will be adding two buttons one to put on hold and another one to remove from on hold so we need to also create enable rules to hide\/show buttons based on the value of our boolean field. so let&#8217;s setup enable three rules first.<\/p>\n<p><strong>To show button only on Open Opportunity<\/strong><br \/>\nWe want to use on hold functionality only for the open opportunities so we need to setup on rule to show our buttons only on the open opportunity form. We are going to use value rule like below.<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHolddialogOpenopp.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4340 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHolddialogOpenopp-300x107.jpg\" alt=\"OnHolddialogOpenopp\" width=\"300\" height=\"107\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHolddialogOpenopp-300x107.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHolddialogOpenopp-624x222.jpg 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHolddialogOpenopp.jpg 946w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Rule to show\/hide OnHold button and Remove On Hold button<\/strong><br \/>\nWe need to setup two another rules which will show button based on the field value.<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4339 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton-300x97.jpg\" alt=\"OnHoldbutton\" width=\"300\" height=\"97\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton-300x97.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton-624x202.jpg 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton.jpg 945w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nAbove rule will show On Hold button when value of the field will be false (opportunity not on hold currently).<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldbutton.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4341 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldbutton-300x104.jpg\" alt=\"RemoveOnHoldbutton\" width=\"300\" height=\"104\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldbutton-300x104.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldbutton-624x215.jpg 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldbutton.jpg 933w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nAbove rule will show button when opportunity will be on Hold.<\/p>\n<p><strong>Adding Commands and buttons<\/strong><br \/>\nNow we need to add command that we will using under the buttons and we need also refer our enable rules there like below:<br \/>\nFor On Hold button<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbuttonCommand.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4343 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbuttonCommand-300x137.jpg\" alt=\"OnHoldbuttonCommand\" width=\"300\" height=\"137\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbuttonCommand-300x137.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbuttonCommand-1024x469.jpg 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbuttonCommand-624x286.jpg 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbuttonCommand.jpg 1121w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>For Remove On Hold button<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldCommand.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4345 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldCommand-300x137.jpg\" alt=\"RemoveOnHoldCommand\" width=\"300\" height=\"137\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldCommand-300x137.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldCommand-1024x466.jpg 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldCommand-624x284.jpg 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnHoldCommand.jpg 1113w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<strong>On Hold Button<\/strong><br \/>\nFinally we need to add button and need to refer commands we created in earlier step<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4342 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton1-300x148.png\" alt=\"OnHoldbutton1\" width=\"300\" height=\"148\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton1-300x148.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton1-1024x505.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton1-624x308.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/OnHoldbutton1.png 1419w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<strong>Remove On Hold button<\/strong><br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnholdbutton1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4344 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnholdbutton1-300x146.png\" alt=\"RemoveOnholdbutton1\" width=\"300\" height=\"146\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnholdbutton1-300x146.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnholdbutton1-1024x499.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnholdbutton1-624x304.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/RemoveOnholdbutton1.png 1361w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now publish your changes and when we will press On Hold button we should get prompt like below:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/onHoldcomment.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4346 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/onHoldcomment-300x176.png\" alt=\"onHoldcomment\" width=\"300\" height=\"176\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/onHoldcomment-300x176.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/onHoldcomment-1024x601.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/onHoldcomment-624x366.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/09\/onHoldcomment.png 1308w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Summary<\/strong><br \/>\nWe discuss how we can add custom bootstrap dialog in D365 and call it from command button.<\/p>\n<p>Hope it will help someone !!<br \/>\n<strong>Keep learning and Keep Sharing !!<\/strong><\/p>\n<h1 class=\"entry-title\"><a href=\"https:\/\/himbap.com\/blog\/?p=4061\">Completing Activity using Custom Ribbon Button<\/a><\/h1>\n","protected":false},"excerpt":{"rendered":"<p>Requirements Let\u2019s say we have requirement where user can put opportunity on hold but before doing he needs to enter comment which should be saved in the opportunity. In the earlier part we discussed of creating prompt and updating opportunity, in this part we will discuss next items. Details We have our prompt page ready now we need to create&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=4334\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":4346,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,21,402,522,25,7,492],"tags":[986,987,988],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4334"}],"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=4334"}],"version-history":[{"count":9,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4334\/revisions"}],"predecessor-version":[{"id":4354,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4334\/revisions\/4354"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/4346"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}