{"id":11487,"date":"2018-04-12T18:27:12","date_gmt":"2018-04-12T12:57:12","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=11487"},"modified":"2018-04-12T18:27:12","modified_gmt":"2018-04-12T12:57:12","slug":"how-to-associate-knowledge-article-with-incident-case-programmatically-in-dynamics-365","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2018\/04\/how-to-associate-knowledge-article-with-incident-case-programmatically-in-dynamics-365\/","title":{"rendered":"How to associate Knowledge Article with Incident (Case) Programmatically in Dynamics 365"},"content":{"rendered":"<h2 style=\"text-align: justify;\"><strong>Introduction:<\/strong><\/h2>\n<p style=\"text-align: justify;\">Microsoft has introduced a knowledge management system for Dynamics CRM 365. This enables users to create rich knowledge articles, which also supports embedding external multimedia content like images and videos in the form of links. It also allows translations and versioning for the articles.<\/p>\n<p style=\"text-align: justify;\">In this blog will discuss about how to associate Knowledge Article with Incident (Case) programmatically.<\/p>\n<p style=\"text-align: justify;\"><strong>Recently<\/strong>, we came across below scenario,<\/p>\n<p style=\"text-align: justify;\">Where User has dropdowns of \u201cKnowledge Article\u201d and \u201cIncident\u201d and one custom button.<\/p>\n<p style=\"text-align: justify;\">If user select values form dropdowns and clicked on the custom button then \u201cKnowledge Article\u201d should associate with selected \u201cIncident\u201d. But we cannot Associate Knowledge Article with Incident (Case) directly without creating custom relationships.<\/p>\n<p style=\"text-align: justify;\">After some research and play around we found the below solution.<\/p>\n<h2 style=\"text-align: justify;\"><strong>Solution:<\/strong><\/h2>\n<p style=\"text-align: justify;\">We used OOB relationships to achieve this. In Dynamics CRM there is one intermediary entity called \u201c<strong>Knowledge Article Entity<\/strong>\u201d between <strong>Incident<\/strong> (case) and <strong>Knowledge Article<\/strong>.<\/p>\n<p style=\"text-align: justify;\">\u201cKnowledge Article Entity\u201d entity have following 2 OOB relationships.<\/p>\n<ol>\n<li style=\"text-align: justify;\">Knowledge Article Entity -&gt; Knowledge Article (N:1)<\/li>\n<li style=\"text-align: justify;\">Knowledge Article Entity -&gt; Case (N:1)<\/li>\n<\/ol>\n<p><img decoding=\"async\" class=\"aligncenter  wp-image-11489\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/04\/How-to-associate-Knowledge-Article-with-Incident-Case-Programmatically-in-Dynamics-365.png\" alt=\"How to associate Knowledge Article with Incident (Case) Programmatically in Dynamics 365\" width=\"828\" height=\"151\" \/><\/p>\n<p style=\"text-align: justify;\">To perform above action, follow the below-mentioned steps:<\/p>\n<p style=\"text-align: justify;\">Steps 1:<\/p>\n<p style=\"text-align: justify;\">Create a new record or used existing record of Knowledge Article and Incident (Case) entity.<\/p>\n<p style=\"text-align: justify;\">Steps 2:<\/p>\n<p style=\"text-align: justify;\">Create new record on \u201cKnowledge Article Entity\u201d entity with following two value.<\/p>\n<ol style=\"text-align: justify;\">\n<li>Knowledge Article Lookup Value (step 1)<\/li>\n<li>Case Lookup Value (step 1)<\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Steps 3:<\/p>\n<p style=\"text-align: justify;\">Associate newly created \u201cKnowledge Article Entity\u201d (created in step 2) entity record with Incident (case).<\/p>\n<p style=\"text-align: justify;\">Refer the code below;<\/p>\n<h2><strong>JavaScript Code<\/strong>:<\/h2>\n<pre class=\"lang:default decode:true \">\/\/Object of \u201cKnowledge Article Entity\u201d\nvar kAIncident = new Object();\n\n\/\/Knowledge Article Lookup\nkAIncident[\"knowledgearticleid@odata.bind\"] = \"\/knowledgearticles(\" + Knowledge Article ID+ \")\";\n\/\/Case Lookup\nkAIncident[\"incidentid@odata.bind\"] = \"\/incidents(\" + Case ID + \")\";\n\ncrmAPI.Create(\"knowledgearticleincidents\", kAIncident).then(function (result) \n{ \nif (isValid(result)) \n{\ncrmAPI.Associate(\"incidents\", caseID, \"knowledgearticle_incidents\", \"knowledgearticleincidents\", result)\n              }\n     \t});\n\nNote : \u201cknowledgearticle_incidents\u201d is a N:1 of relationship between Incident (case) and Knowledge Article Entity\n<\/pre>\n<h2>\u00a0<strong>C# Code:<\/strong><\/h2>\n<pre class=\"lang:default decode:true \">Guid kAIncident_id = new Guid();\n\/\/Object of \u201cKnowledge Article Entity\u201d\nEntity kAIncident = new Entity(\"knowledgearticleincident\");\n\n\/\/Knowledge Article Lookup\nkAIncident[\"knowledgearticleid\"] = new EntityReference(\"knowledgearticle\", new Guid(\u201cKnowledge Article ID\u201d));\n\n\/\/Case Lookup \nkAIncident[\"incidentid\"] = new EntityReference(\"incident\", new Guid(\"Case ID\"));\n\nkAIncident_id = _service.Create(kAIncident);\n\n\nEntityReferenceCollection relatedEntities = new EntityReferenceCollection();\n        \nrelatedEntities.Add(new EntityReference(\"knowledgearticleincident\", new Guid(kAIncident_id.ToString())));\n\nRelationship newRelationship = new Relationship(\"knowledgearticle_incidents\"); \n\n\/\/Associate the knowledge article record with the Case record.         \n_service.Associate(\"incident\", new Guid(\"Case ID\"), newRelationship, relatedEntities);\n<\/pre>\n<p>&nbsp;<\/p>\n<h2><strong>Conclusion:<\/strong><\/h2>\n<p style=\"text-align: justify;\">Using solution described above the user can <strong>Associate Knowledge Article with Incident (Case) programmatically <\/strong>using OOB relationships in Dynamics 365.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/product\/productivity-pack\/click-2-export-microsoft-dynamics-crm-reports\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter  wp-image-10864\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2017\/12\/Click2Export-banner.png\" alt=\"Export Dynamics CRM Reports\" width=\"824\" height=\"206\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Microsoft has introduced a knowledge management system for Dynamics CRM 365. This enables users to create rich knowledge articles, which also supports embedding external multimedia content like images and videos in the form of links. It also allows translations and versioning for the articles. In this blog will discuss about how to associate Knowledge\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2018\/04\/how-to-associate-knowledge-article-with-incident-case-programmatically-in-dynamics-365\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":11488,"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,18,19],"tags":[154,155],"class_list":["post-11487","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","category-dynamics-365-v9-2","category-dynamics-crm","tag-associate-knowledge-article","tag-associate-knowledge-article-dynamics-365"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/11487","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=11487"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/11487\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/11488"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=11487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=11487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=11487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}