{"id":31025,"date":"2022-03-17T17:52:01","date_gmt":"2022-03-17T12:22:01","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=31025"},"modified":"2022-03-17T17:52:01","modified_gmt":"2022-03-17T12:22:01","slug":"add-functionality-on-opening-of-a-knowledge-article-using-the-addonresultopened-api","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2022\/03\/add-functionality-on-opening-of-a-knowledge-article-using-the-addonresultopened-api\/","title":{"rendered":"Add functionality on opening of a knowledge article using the addOnResultOpened API"},"content":{"rendered":"<h2><strong>Introduction:<\/strong><\/h2>\n<p>As we all know, Microsoft\u2019s most recent release of the Client API References includes a slew of new features. Microsoft offers several Client APIs that allow developers to seamlessly interface with Dynamics 365 CRM.<\/p>\n<p>In this blog we\u2019ll look at one of the Client APIs that uses Knowledge Base Search Control and call specific function whenever any Knowledge Article is opened from the search result.<\/p>\n<h2><strong>addOnResultOpened Client API Reference:<\/strong><\/h2>\n<p>When we search any article in Knowledge Base Search Control using the Keywords based on our requirement, we get the list of knowledge articles that has been published and after selecting\/opening any article from the search result, <a href=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/developer\/model-driven-apps\/clientapi\/reference\/controls\/addonresultopened\" target=\"_blank\" rel=\"noopener\"><strong>addOnResultOpened<\/strong><\/a> Client API will call some other function and perform the specified task which has been defined in that function.<\/p>\n<p>The <strong>addOnResultOpened <\/strong>method accepts only one parameter of type <strong>Function, which will be added to the OnResultOpened<\/strong> Event of Knowledge Base Search Control<strong>.<\/strong><\/p>\n<p><strong>OnResultOpened<\/strong> event occurs when a knowledge base article is opened in knowledge base search control in pop-out window or in inline.<\/p>\n<h2><strong>Use Case: <\/strong><\/h2>\n<p>In this blog, we will demonstrate how to use the above Client API by implementing a simple use case in which when user opens any knowledge article from the knowledge base search result, then using <strong>addOnResultOpened<\/strong> we will call custom JavaScript function which will create <strong>Email Activity<\/strong> record in CRM to acknowledge a user that their knowledge article has been opened by some user.<\/p>\n<p>In this blog we have used Account Entity form on which we are going to implement this use case. We have added new tab on the Account entity form named \u201c<strong>Knowledge Base Tab<\/strong>\u201d which contains the Knowledge Base Search Control as shown in below screenshot:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31031\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/1addOnResultOpened-API.jpeg\" alt=\"addOnResultOpened API\" width=\"1348\" height=\"570\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/1addOnResultOpened-API.jpeg 1348w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/1addOnResultOpened-API-300x127.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/1addOnResultOpened-API-1024x433.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/1addOnResultOpened-API-768x325.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/1addOnResultOpened-API-660x279.jpeg 660w\" sizes=\"(max-width: 1348px) 100vw, 1348px\" \/><\/p>\n<p>To add Knowledge Base Search Control, you can follow the steps given below:<\/p>\n<p>Go to <strong>Advance Settings<\/strong> -&gt; <strong>Customizations<\/strong> -&gt; <strong>Customize the System<\/strong> -&gt; Expand the <strong>Entity.<\/strong><\/p>\n<p>Click on the entity on which you want to add Knowledge Base Search Control. Before adding the Knowledge Base Search Control, you need to make sure that the Entity on which you are adding this control is enabled for <strong>Knowledge Management<\/strong>. If Knowledge Management is not enabled for that entity, then you will not be able to add this control.<\/p>\n<p>To enable the <strong>Knowledge Management<\/strong>, you need to select the checkbox for Knowledge Management on Entity form as shown in below screenshot.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31030\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/2addOnResultOpened-API.jpeg\" alt=\"addOnResultOpened API\" width=\"787\" height=\"498\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/2addOnResultOpened-API.jpeg 787w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/2addOnResultOpened-API-300x190.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/2addOnResultOpened-API-768x486.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/2addOnResultOpened-API-660x418.jpeg 660w\" sizes=\"(max-width: 787px) 100vw, 787px\" \/><\/p>\n<p>After enabling this feature, you need to save and publish the customization to make sure that the settings have been successfully saved and enabled.<\/p>\n<p>Now Expand the Account entity and click on form and open the form on which you want to add Knowledge Base Search Control.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31029\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/3addOnResultOpened-API.jpeg\" alt=\"addOnResultOpened API\" width=\"1364\" height=\"526\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/3addOnResultOpened-API.jpeg 1364w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/3addOnResultOpened-API-300x116.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/3addOnResultOpened-API-1024x395.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/3addOnResultOpened-API-768x296.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/3addOnResultOpened-API-660x255.jpeg 660w\" sizes=\"(max-width: 1364px) 100vw, 1364px\" \/><\/p>\n<p>Once the form is opened, then go to <strong>Insert<\/strong> tab and add <strong>Knowledge Base Search Control<\/strong> on the form section where you want to add this control.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31028\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/4addOnResultOpened-API.jpeg\" alt=\"addOnResultOpened API\" width=\"1366\" height=\"612\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/4addOnResultOpened-API.jpeg 1366w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/4addOnResultOpened-API-300x134.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/4addOnResultOpened-API-1024x459.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/4addOnResultOpened-API-768x344.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/4addOnResultOpened-API-660x296.jpeg 660w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p>We have added <strong>Knowledge Base Search Control<\/strong> on the \u201c<strong>Knowledge Base Tab<\/strong>\u201d tab inside \u201c<strong>Knowledge Base Section<\/strong>\u201d section.<\/p>\n<p>Once Knowledge Base Search Control is successfully added on the entity form, now we are going to write JavaScript code to implement <strong>addOnResultOpened<\/strong> Client API.<\/p>\n<pre class=\"lang:css gutter:true start:1\">\/\/ A namespace defined for New\r\n\r\nvar New = window.New || {};\r\n\r\n\u00a0\r\n\r\nNew.KBSearchOnResultOpened = function (executionContext) {\r\n\r\ntry {\r\n\r\n\/\/Getting the Form Context Object\r\n\r\nvar formContext = executionContext.getFormContext();\r\n\r\n\/\/Getting the knowledge base search control\r\n\r\nvar myKBSearchControl = formContext.getControl('Account_KBArticles');\r\n\r\n\/\/Calling addOnResultOpened function\r\n\r\nmyKBSearchControl.addOnResultOpened(New.OnResultOpened);\r\n\r\n}\r\n\r\ncatch (err) {\r\n\r\nconsole.log(\"Inside Catch -&gt; \" + err.message);\r\n\r\n}\r\n\r\n}\r\n\r\n\u00a0\r\n\r\n\/\/Function that need to be called when knowledge article is opened from knowledge search result\r\n\r\nNew.OnResultOpened = function () {\r\n\r\nvar confirmStringsMessage = { text: \"Do you require any assistance?\", title: \"Confirmation Dialog\" };\r\n\r\nvar confirmMessageOptions = { height: 200, width: 450 };\r\n\r\n\u00a0\r\n\r\nXrm.Navigation.openConfirmDialog(confirmStringsMessage, confirmMessageOptions).then(\r\n\r\nfunction (success) {\r\n\r\nif (success.confirmed) {\r\n\r\n\/\/Getting logged in user's userid\r\n\r\nvar userID = Xrm.Page.context.getUserId().replaceAll(\"{\", \"\").replaceAll(\"}\", \"\");\r\n\r\n\/\/getting username of logged in user\r\n\r\nvar userName = Xrm.Page.context.getUserName();\r\n\r\n\/\/getting the current record ID\r\n\r\nvar currentRecordID = Xrm.Page.data.entity.getId().replaceAll(\"{\", \"\").replaceAll(\"}\", \"\");\r\n\r\nconsole.log(\"userID : \" + userID + \" and userName : \" + userName);\r\n\r\n\u00a0\r\n\r\n\/\/creating data object which is used to passed as parameter while creating email activity\r\n\r\nvar data = {\r\n\r\n\"description\": \"Knowledge Base Article has beed viewed by user - \" + userName, \u00a0 \/\/\/Email Body\r\n\r\n\"regardingobjectid_account@odata.bind\": \"\/accounts(\" + currentRecordID + \")\",\r\n\r\n\"subject\": \"Knowledge Base Search Article bas been viewed by somenone\",\r\n\r\n\"email_activity_parties\": [\r\n\r\n{\r\n\r\n\"partyid_systemuser@odata.bind\": \"\/systemusers(\" + userID + \")\",\r\n\r\n\"participationtypemask\": 1 \u00a0 \/\/From Email\r\n\r\n},\r\n\r\n{\r\n\r\n\"partyid_account@odata.bind\": \"\/systemusers(6a6b321f-e897-ec11-b400-000d3aca14a7)\",\r\n\r\n\"participationtypemask\": 2 \/\/To Email\r\n\r\n}\r\n\r\n]\r\n\r\n};\r\n\r\n\u00a0\r\n\r\n\/\/Creating the Email activity record\r\n\r\nXrm.WebApi.createRecord(\"email\", data).then(\r\n\r\nfunction success(result) {\r\n\r\nconsole.log(\"Email has been created with ID : \" + result.id);\r\n\r\n},\r\n\r\nfunction Error(e) {\r\n\r\nconsole.log(\"New.OnResultOpened -&gt; \" + e.message);\r\n\r\n}\r\n\r\n)\r\n\r\n}\r\n\r\nelse {\r\n\r\nconsole.log(\"Confirmation dialog has been closed by close button.\");\r\n\r\n}\r\n\r\n});\r\n\r\n}\r\n\r\n<\/pre>\n<p>After done with the JavaScript we are going to add this JavaScript file as a WebResource in our CRM Environment. And call <strong>New.KBSearchOnResultOpened<\/strong> function on tab selection changes event, since Knowledge Base Search Control does not have any event.<\/p>\n<p>After doing this we are all set to go and test what will happen when we select any knowledge article in knowledge base search result.<\/p>\n<h2><strong>Demonstration:<\/strong><\/h2>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31027\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/5addOnResultOpened-API.jpeg\" alt=\"addOnResultOpened API\" width=\"1366\" height=\"565\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/5addOnResultOpened-API.jpeg 1366w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/5addOnResultOpened-API-300x124.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/5addOnResultOpened-API-1024x424.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/5addOnResultOpened-API-768x318.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/5addOnResultOpened-API-660x273.jpeg 660w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p>The scenario which we are considering is that there would be a support user whose job is to help the salespersons with their queries. So, the functionality which we have implemented is any time a salesperson opens a knowledge article, our logic would ask if they require any assistance. If yes then a notification will be send via email to the support user.<\/p>\n<p>So based on this scenario the logic in our WebResource is &#8211; when we select\/open any record, then <strong>addOnResultOpened<\/strong> will trigger and it will display a dialog message asking \u201c<strong>Do you require any assistance?<\/strong>\u201d. If the users opt for \u2018Yes\u2019 then an Email activity will get created which we can see in the <strong>Timeline<\/strong> section of the current account record.<\/p>\n<p>In the <strong>Timeline<\/strong> section we can see that the Email activity has been created as shown in below image:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31026\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/6addOnResultOpened-API.jpeg\" alt=\"addOnResultOpened API\" width=\"993\" height=\"492\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/6addOnResultOpened-API.jpeg 993w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/6addOnResultOpened-API-300x149.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/6addOnResultOpened-API-768x381.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/6addOnResultOpened-API-660x327.jpeg 660w\" sizes=\"(max-width: 993px) 100vw, 993px\" \/><\/p>\n<h2><strong>Conclusion:<\/strong><\/h2>\n<p>Thus, we saw how using the <strong>addOnResultOpened<\/strong> Client API, we can further implement additional functionality on opening of a knowledge article.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/add-manage-schedule-notifications-alerts-4-dynamics-365-crm\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone  wp-image-31032\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/A4D.jpg\" alt=\"\" width=\"832\" height=\"208\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/A4D.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/A4D-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/A4D-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/03\/A4D-660x165.jpg 660w\" sizes=\"(max-width: 832px) 100vw, 832px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: As we all know, Microsoft\u2019s most recent release of the Client API References includes a slew of new features. Microsoft offers several Client APIs that allow developers to seamlessly interface with Dynamics 365 CRM. In this blog we\u2019ll look at one of the Client APIs that uses Knowledge Base Search Control and call specific\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2022\/03\/add-functionality-on-opening-of-a-knowledge-article-using-the-addonresultopened-api\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[16,2361],"tags":[],"class_list":["post-31025","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-technical"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/31025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=31025"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/31025\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=31025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=31025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=31025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}