{"id":27685,"date":"2021-04-29T12:10:08","date_gmt":"2021-04-29T12:10:08","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=27685"},"modified":"2021-09-02T06:36:11","modified_gmt":"2021-09-02T06:36:11","slug":"retrieving-data-and-displaying-icons-on-dynamics-365-view-columns","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2021\/04\/retrieving-data-and-displaying-icons-on-dynamics-365-view-columns\/","title":{"rendered":"Retrieving data and displaying icons on Dynamics 365 view columns"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Showing meaningful icons alongside view columns is a great visual experience to have in the Microsoft Dynamics 365 apps. It quickly gives an idea to the user about what kind of record it is.<\/p>\n<p>Microsoft had added this capability to show icons alongside the View columns in 2016.<\/p>\n<p>If you check <a href=\"https:\/\/www.inogic.com\/blog\/2016\/12\/add-custom-icons-and-tooltip-to-dynamics-365-columns-in-views\/\" target=\"_blank\" rel=\"noopener noreferrer\">our older blog<\/a>, you will see a simple logic that shows the icon based on the value present on the field\/column. However, what if we want to show icons based on the value retrieved from other entities\/tables?<br \/>\nIn this blog, we see how to do this.<\/p>\n<p>Let us consider a scenario where we want to show different icons against the Company in Contact view based on the Banking Type field present on the related Bank Details record of Account.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27677 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/1-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns.jpeg\" alt=\"Retrieve data and display icons to Dynamics 365 view columns\" width=\"813\" height=\"266\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/1-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns.jpeg 813w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/1-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns-300x98.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/1-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns-768x251.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/1-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns-660x216.jpeg 660w\" sizes=\"(max-width: 813px) 100vw, 813px\" \/><\/p>\n<p>Here type is the optionset\/dropdown with two values i.e. Preferred and Classic.<br \/>\nWe need to retrieve the Account entity record along with its banking details and need to return the icons based on the value of the Type field.<\/p>\n<p><strong>Prerequisites &#8211;<\/strong><\/p>\n<p>\u2022 Create web resources for Preferred and Classic and Default<br \/>\n\u2022 Create a JavaScript web resource to determine which icon to show on the Dynamics 365 view columns by retrieving the data.<\/p>\n<p>Below are the three different web resources created to store the icons for each type:<\/p>\n<p>1) New_\/preferred.png<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-27680 alignleft\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/4-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns.jpg\" alt=\"Retrieve data and display icons to Dynamics 365 view columns\" width=\"28\" height=\"25\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>2) New_\/classic.png<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-27681 alignleft\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/5-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns.jpg\" alt=\"Retrieve data and display icons to Dynamics 365 view columns\" width=\"26\" height=\"26\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>3) New_\/default.png<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-27682 alignleft\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/6-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns.png\" alt=\"Retrieve data and display icons to Dynamics 365 view columns\" width=\"24\" height=\"24\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Below is the JavaScript function binding to the column \u201cCompany\u201d of the \u201cAll Contacts\u201d view.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27678 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/2-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns.jpeg\" alt=\"Retrieve data and display icons to Dynamics 365 view columns\" width=\"483\" height=\"488\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/2-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns.jpeg 483w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/2-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns-297x300.jpeg 297w\" sizes=\"(max-width: 483px) 100vw, 483px\" \/><\/p>\n<p>JavaScript Code:<br \/>\nfunction displacySyncStatusIcon(rowData, userLCID) {<br \/>\n\/\/read the row<br \/>\nvar row = JSON.parse(rowData);<br \/>\nvar companyId = row.parentcustomerid_Value.Id._formattedGuid;\/\/ get guid of the company<br \/>\nvar companyLogicalName = row.parentcustomerid_Value.LogicalName;<br \/>\nvar imgName = &#8220;&#8221;;<br \/>\nvar tooltip = &#8220;&#8221;;<\/p>\n<p>var fetchXml = &#8220;&lt;fetch version=&#8217;1.0&#8242; output-format=&#8217;xml-platform&#8217; mapping=&#8217;logical&#8217; distinct=&#8217;false&#8217;&gt;&#8221; +<br \/>\n&#8220;&lt;entity name=&#8217;account&#8217;&gt;&#8221; +<br \/>\n&#8220;&lt;attribute name=&#8217;name&#8217; \/&gt;&#8221; +<br \/>\n&#8220;&lt;attribute name=&#8217;primarycontactid&#8217; \/&gt;&#8221; +<br \/>\n&#8220;&lt;attribute name=&#8217;telephone1&#8242; \/&gt;&#8221; +<br \/>\n&#8220;&lt;attribute name=&#8217;accountid&#8217; \/&gt;&#8221; +<br \/>\n&#8220;&lt;order attribute=&#8217;name&#8217; descending=&#8217;false&#8217; \/&gt;&#8221; +<br \/>\n&#8220;&lt;filter type=&#8217;and&#8217;&gt;&#8221; +<br \/>\n&#8220;&lt;condition attribute=&#8217;accountid&#8217; operator=&#8217;eq&#8217; value='&#8221; + companyId + &#8220;&#8216; \/&gt;&#8221; +<br \/>\n&#8220;&lt;\/filter&gt;&#8221; +<br \/>\n&#8220;&lt;link-entity name=&#8217;new_bankingdetails&#8217; from=&#8217;new_bankingdetailsid&#8217; to=&#8217;new_bankingdetails&#8217; visible=&#8217;false&#8217; link-type=&#8217;outer&#8217; alias=&#8217;bankingdetails&#8217;&gt;&#8221; +<br \/>\n&#8220;&lt;attribute name=&#8217;new_type&#8217; \/&gt;&#8221; +<br \/>\n&#8220;&lt;\/link-entity&gt;&#8221; +<br \/>\n&#8220;&lt;\/entity&gt;&#8221; +<br \/>\n&#8220;&lt;\/fetch&gt;&#8221;;<br \/>\nfetchXml = &#8220;?fetchXml=&#8221; + encodeURIComponent(fetchXml);<br \/>\n\/\/@ts-ignore<br \/>\nreturn new Promise(function (resolve, reject) {<br \/>\n\/\/@ts-ignore<br \/>\nXrm.WebApi.retrieveMultipleRecords(&#8220;account&#8221;, fetchXml).then(function (result) {<br \/>\nvar bankingRecord = result != null &amp;&amp; result.entities != null &amp;&amp; result.entities[0] != null ? result.entities[0] : null;<br \/>\nvar type = bankingRecord[&#8220;bankingdetails.new_type&#8221;] != null ? bankingRecord[&#8220;bankingdetails.new_type&#8221;] : null;<br \/>\nswitch (type) {<br \/>\ncase 100000000:\/\/preferred<br \/>\nimgName = &#8220;new_\/preferred.png&#8221;;<br \/>\ntooltip = &#8220;Preferred Banking Account&#8221;;<br \/>\nbreak;<br \/>\ncase 100000001:\/\/classic<br \/>\nimgName = &#8220;new_\/classic.png&#8221;;<br \/>\ntooltip = &#8220;Classic Banking Account&#8221;;<br \/>\nbreak;<br \/>\ndefault:<br \/>\nimgName = &#8220;new_\/default.png&#8221;;<br \/>\ntooltip = &#8220;Regular Banking Account&#8221;;<br \/>\nbreak;<br \/>\n}<br \/>\nvar resultarray = [imgName, tooltip];<br \/>\n\/\/resolve in success callback<br \/>\nresolve(resultarray);<br \/>\n}).catch(function (err) {<br \/>\nreject(err);<br \/>\nconsole.log(err);<br \/>\n});<br \/>\n});<br \/>\n}<\/p>\n<p>We have retrieved the record using Xrm.WebApi.retrieveMultipleRecords function inside the promise object. On success call-back of retrieve, we need to resolve the promise by passing the array containing the icon and the tooltip.<\/p>\n<p><strong>Note: This works only on Unified Interface.<\/strong><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27679 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/3-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns.jpeg\" alt=\"Retrieve data and display icons to Dynamics 365 view columns\" width=\"863\" height=\"366\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/3-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns.jpeg 863w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/3-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns-300x127.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/3-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns-768x326.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/3-Retrieve-data-and-display-icons-to-Dynamics-365-view-columns-660x280.jpeg 660w\" sizes=\"(max-width: 863px) 100vw, 863px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>Using the above method we can show icons alongside View columns by retrieving the data using promise.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/click-2-export-microsoft-dynamics-crm-reports\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-27695 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/c2e.jpg\" alt=\"\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/c2e.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/c2e-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/c2e-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/04\/c2e-660x165.jpg 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Showing meaningful icons alongside view columns is a great visual experience to have in the Microsoft Dynamics 365 apps. It quickly gives an idea to the user about what kind of record it is. Microsoft had added this capability to show icons alongside the View columns in 2016. If you check our older blog,\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2021\/04\/retrieving-data-and-displaying-icons-on-dynamics-365-view-columns\/\">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":[1],"tags":[2386],"class_list":["post-27685","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-dynamics-365-view-columns"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/27685","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=27685"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/27685\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=27685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=27685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=27685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}