{"id":4325,"date":"2022-08-31T15:39:33","date_gmt":"2022-08-31T15:39:33","guid":{"rendered":"https:\/\/himbap.com\/blog\/?p=4325"},"modified":"2022-09-01T05:27:11","modified_gmt":"2022-09-01T05:27:11","slug":"implementing-prompt-dialog-in-d365-part-1","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=4325","title":{"rendered":"Implementing Prompt dialog in D365 CE Part 1"},"content":{"rendered":"<p><strong>Requirements<\/strong><br \/>\nLet&#8217;s 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><strong>Details<\/strong><br \/>\nLet&#8217;s say we want to implement this requirement using prompt dialog where user can provide comments before setting opportunity on hold. To implement this requirement we have to do following things:<\/p>\n<p>1. Create Dialog page (I am building bootstrap dialog for demo)<br \/>\n2. Script to update opportunity<br \/>\n3. Script for calling our dialog page<br \/>\n4.Calling this dialog button from command button<\/p>\n<p>In this post I am going to complete step 1 and 2 so let&#8217;s do it.<\/p>\n<p><strong>Create Dialog page<\/strong><br \/>\nTo build bootstrap dialog we can use following code, I am building a simple dialog with comment field and save button.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;html&gt;\r\n   &lt;head&gt;\r\n      &lt;title&gt;On Hold Comment&lt;\/title&gt;\r\n      &lt;script src=&quot;ClientGlobalContext.js.aspx&quot; type=&quot;text\/javascript&quot;&gt;&lt;\/script&gt;\r\n      &lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.4.1\/css\/bootstrap.min.css&quot;&gt;\r\n      &lt;script type=&quot;text\/javascript&quot; src=&quot;https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js&quot;&gt;&lt;\/script&gt;\r\n      &lt;script type=&quot;text\/javascript&quot;&gt;\/\/place code here&lt;\/script&gt;\r\n\r\n&lt;style&gt;\r\n         #AddNewType {\r\n         display: none;\r\n         }\r\n         #PanelOpportunity {\r\n         display: none;\r\n         }\r\n         #lookUpOpportunity {\r\n         display: none;\r\n         }\r\n         body {\r\n         min-height: 100%;\r\n         min-width: 100%;\r\n         }\r\n         .overView {\r\n         display: block;\r\n         min-height: 100% !important;\r\n         min-width: 100% !important;\r\n         background-color: slategrey;\r\n         position: absolute;\r\n         z-index: 5;\r\n         opacity: 0.7;\r\n         top: 0px;\r\n         left: 0px;\r\n         }\r\n         .right {\r\n         float: right;\r\n         }\r\n         .isModel {\r\n         background-color: goldenrod;\r\n         width: 25%;\r\n         height: 450px;\r\n         }\r\n         .requied::after {\r\n         content: &quot; *&quot;;\r\n         color: orangered;\r\n         }\r\n      &lt;\/style&gt;\r\n\r\n   &lt;\/head&gt;\r\n   &lt;body style=&quot;overflow-wrap: break-word;&quot;&gt;\r\n\r\n&lt;div class=&quot;modal2&quot; tabindex=&quot;-1&quot; role=&quot;dialog&quot;&gt;\r\n\r\n&lt;div class=&quot;modal-content&quot;&gt;\r\n\r\n&lt;div class=&quot;modal-body&quot;&gt;\r\n\r\n&lt;form id=&quot;my-form&quot;&gt;\r\n\r\n&lt;div class=&quot;form-group&quot;&gt;\r\n                     &lt;textarea class=&quot;form-control requied&quot; id=&quot;comment&quot; rows=&quot;3&quot; size=&quot;250&quot; maxlength=&quot;250&quot; required=&quot;&quot;&gt;&lt;\/textarea&gt;\r\n                     &lt;button type=&quot;submit&quot; style=&quot;color: #fff; background: rgb(216, 59, 0);&quot; onclick=&quot;UpdateOpportunity()&quot; class=&quot;btn btn-default right&quot;&gt;Save&lt;\/button&gt;\r\n                  &lt;\/div&gt;\r\n\r\n               &lt;\/form&gt;\r\n\r\n            &lt;\/div&gt;\r\n\r\n         &lt;\/div&gt;\r\n\r\n      &lt;\/div&gt;\r\n\r\n   &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<p>In the first part of the code we are referencing dynamics script, CSS and other bootstrap libraries. above code will produce dialog like below:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/08\/OnHolddialog.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4331 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/08\/OnHolddialog-300x164.jpg\" alt=\"OnHolddialog\" width=\"300\" height=\"164\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/08\/OnHolddialog-300x164.jpg 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2022\/08\/OnHolddialog.jpg 522w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><strong>Update Opportunity<\/strong><br \/>\nLet&#8217;s say we have one boolean field on the opportunity which we will be setting if it is on hold. To update opportunity we need to get the opportunity id, comments that user will be entering into the comment dialog box. first to get the opportunity id we are going to parse the url parameter like below:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar param = null;\r\n$(document).ready(function() {\r\n    param = getUrlParameter('data');\r\n    console.log(param);\r\n});\r\n\r\nfunction getUrlParameter(urlparam) {\r\n\r\n    var pageURL = window.location.search.substring(1),\r\n        urlVariables = pageURL.split('?'),\r\n        parameterName,\r\n        i;\r\n\r\n    for (i = 0; i &lt; urlVariables.length; i++) {\r\n        parameterName = urlVariables[i].split('=');\r\n\r\n        if (parameterName[0] === urlparam) {\r\n            return parameterName[1] === undefined ? true : decodeURIComponent(parameterName[1]);\r\n        }\r\n    }\r\n}\r\n\r\n<\/pre>\n<p>using above code we will get opportunity id which we are going to use in below code to update opportunity:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction UpdateOpportunity() {\r\n    var commentBox = document.getElementById(&quot;comment&quot;).value;\r\n    if (commentBox.length == 0)\r\n        return;\r\n    else {\r\n        debugger;\r\n        var data = {\r\n            &quot;him_placeonhold&quot;: true,\r\n            &quot;him_onholdcomment&quot;: document.getElementById(&quot;comment&quot;).value\r\n        }\r\n        parent.Xrm.WebApi.updateRecord(&quot;opportunity&quot;, param, data).then(\r\n            function success(result) {\r\n                parent.location.reload();\r\n                parent.$(&quot;button[data-id='dialogCloseIconButton']&quot;, parent.document).click();\r\n            },\r\n            function(error) {\r\n                console.log(error);\r\n            }\r\n        );\r\n    }\r\n}\r\n<\/pre>\n<p>In above code I am using WebApi.updateRecord method and you can see as this is an html page so I have to use parent.Xrm to refer WebApi methods. parent.Xrm is supported for html page. Once opportunity update request is done I am closing the dialog button. We can place all java script methods under the script block.<\/p>\n<p><strong>Summary<\/strong><br \/>\nIn this post we discussed about creating prompt dialog and update opportunity based on the comment. In Next part we will discuss pending items so stay tuned !<\/p>\n<p>Hope it will help someone !!<br \/>\n<strong>Keep learning and Keep Sharing !!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Requirements Let&#8217;s 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. Details Let&#8217;s say we want to implement this requirement using prompt dialog where user can provide comments before setting opportunity on hold. To implement this requirement we have to do following things:&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=4325\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":4331,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,402,522,7,492],"tags":[981,980,982,984,983,985],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4325"}],"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=4325"}],"version-history":[{"count":9,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4325\/revisions"}],"predecessor-version":[{"id":4353,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4325\/revisions\/4353"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/4331"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}