{"id":10895,"date":"2017-12-13T17:53:19","date_gmt":"2017-12-13T12:23:19","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=10895"},"modified":"2017-12-13T17:53:19","modified_gmt":"2017-12-13T12:23:19","slug":"read-formatted-values-using-linq-queries-in-dynamics-365","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2017\/12\/read-formatted-values-using-linq-queries-in-dynamics-365\/","title":{"rendered":"Read Formatted values using LINQ Queries in Dynamics 365"},"content":{"rendered":"<p style=\"text-align: justify;\">Recently we had a business requirement where we came across an issue while retrieving formatted values using LINQ.<\/p>\n<p style=\"text-align: justify;\">In this blog, we will discuss how to resolve this issue.<\/p>\n<p style=\"text-align: justify;\">Suppose, we want to retrieve a revenue with currency symbol in the formatted value and we are using below query:<!--more--><\/p>\n<pre class=\"lang:default decode:true\">\/\/Retrieve Account List with Name &amp; Revenue\n var accountList = (from acc in _context.CreateQuery(\"account\")\n                      select new\n                      {\n\n                accName = acc.GetAttributeValue&lt;string&gt;(\"name\"),\n\n               revenue = acc.FormattedValues.Contains(\"revenue\")? acc.FormattedValues[\"revenue\"]: \"No Data\"\n\n                                   }).ToList();\n<\/pre>\n<p style=\"text-align: justify;\">\u00a0It seems to be correct, but it fails to retrieve the revenue value with a currency symbol.<\/p>\n<p style=\"text-align: justify;\">Instead, we were just getting \u201cNo Data\u201d as the value which we have set if no revenue value found.<\/p>\n<p style=\"text-align: justify;\">After some research and play around we found that the FormattedValues are not returned directly as shown above.<\/p>\n<p style=\"text-align: justify;\">For that we needed to change the query to:<\/p>\n<pre class=\"lang:default decode:true \">\/\/Retrieve Account List with Name &amp; Revenue\n   var accountList = (from acc in _context.CreateQuery(\"account\")\n                        select new\n                      {\n\n                        accName = acc.GetAttributeValue&lt;string&gt;(\"name\"),\n\n              revenueField = acc.Attributes.Contains(\"revenue\") ? acc[\"revenue\"] : null,\n         revenue = acc.FormattedValues.Contains(\"revenue\") ? acc.FormattedValues[\"revenue\"] : \"No Data\"\n\n                                   }).ToList();\n<\/pre>\n<p>And then it worked!<\/p>\n<h2><strong>Conclusion:<\/strong><\/h2>\n<p>If we need to retrieve a Formattedvalue using LINQ, then we first need to read the attribute value, and then we may read the FormattedValues later in the query for that attribute.<\/p>\n<p><a href=\"http:\/\/www.inogic.com\/product\/integrations\/inolink-quickbooks-microsoft-dynamics-crm\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter  wp-image-10684\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/08\/Microsoft-Dynamics-CRM-and-QuickBooks-Integration.png\" alt=\"Microsoft Dynamics CRM and QuickBooks Integration\" width=\"824\" height=\"206\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently we had a business requirement where we came across an issue while retrieving formatted values using LINQ. In this blog, we will discuss how to resolve this issue. Suppose, we want to retrieve a revenue with currency symbol in the formatted value and we are using below query:<\/p>\n","protected":false},"author":13,"featured_media":10896,"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,19,42,67],"tags":[993],"class_list":["post-10895","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","category-dynamics-crm","category-plugin","category-workflows","tag-linq-queries"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/10895","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=10895"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/10895\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/10896"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=10895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=10895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=10895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}