{"id":12525,"date":"2018-07-30T17:27:43","date_gmt":"2018-07-30T11:57:43","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=12525"},"modified":"2018-07-30T17:27:43","modified_gmt":"2018-07-30T11:57:43","slug":"how-to-retrieve-sitemap-xml-programmatically-in-dynamic-365","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2018\/07\/how-to-retrieve-sitemap-xml-programmatically-in-dynamic-365\/","title":{"rendered":"How to Retrieve SiteMap XML programmatically in Dynamic 365"},"content":{"rendered":"<h2><strong>Introduction:<\/strong><\/h2>\n<p style=\"text-align: justify;\">We can edit Sitemap by using Microsoft Dynamic SiteMap Designer or SiteMap Editor using XrmToolBox. Whereas we can also update SiteMap programmatically, but before updating SiteMap we have to retrieve SiteMap XML programmatically.<\/p>\n<p style=\"text-align: justify;\">So in this blog, we will discuss about how to retrieve SiteMap XML programmatically.<\/p>\n<p style=\"text-align: justify;\">Recently, we came across below scenario, Where user wants to update default as well as app specific SiteMap programmatically. After some research we found the below solution.<\/p>\n<h2><strong>Solution:<\/strong><\/h2>\n<p style=\"text-align: justify;\">We can used Fetch Expression<strong>, <\/strong>Linq and QueryExpression to retrieve app\/default <strong>SiteMap<\/strong> XML<\/p>\n<p style=\"text-align: justify;\"><strong>1<\/strong>. Retrieve SiteMap using FetchExpression :<\/p>\n<p style=\"text-align: justify;\">In the fetch expression, it will gives only one sitemap i.e. default <strong>SiteMap<\/strong> entity into the entity collection.<\/p>\n<pre class=\"lang:default decode:true \">string fetchXML = @\"&lt;fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' &gt;\n&lt;entity name='sitemap' \/&gt;\n&lt;attribute name='sitemapxml' \/&gt;              \n&lt;\/fetch&gt;\";\n\nEntityCollection collection = _service.RetrieveMultiple(new FetchExpression(fetchXML));\n<\/pre>\n<p><strong>2<\/strong>. Retrieve SiteMap using Linq:<\/p>\n<p>We can get App specific\/default SiteMap using linq. It will give single entity in result set:<\/p>\n<pre class=\"lang:default decode:true \">Entity sitemapEntity = (from c in _context.CreateQuery(\"sitemap\")\nselect c).ToList().FirstOrDefault();\n<\/pre>\n<p>To retrieve app specific <strong>SiteMap<\/strong>, we have to pass app <strong>SiteMap<\/strong> name in filter condition (used sitemapnameunique attribute)<\/p>\n<pre class=\"lang:default decode:true\">Entity sitemapEntity = (from c in _context.CreateQuery(\"sitemap\")\nWhere ((string)c[\"sitemapnameunique\"]).Contains(\"customerservice\")\nselect c).ToList().FirstOrDefault();<\/pre>\n<blockquote><p><strong>Note<\/strong>: &#8211; In above linq &#8211; \u201ccustomerservice\u201d is a name of sitemap.<\/p><\/blockquote>\n<p><strong>3<\/strong>. Retrieve SiteMap using QueryExpression :<\/p>\n<p>With the help of query expression we can get multiple site map at one time.<\/p>\n<p>Create collection of <strong>SiteMap<\/strong> name.<\/p>\n<pre class=\"lang:default decode:true\">string[] arrofAppSiteMap = { \"AppforOutlookSiteMap\", \"customerservice\", \"Customerservicehub\", \"SalesHubSitemap\", \"SalesSiteMap\"};<\/pre>\n<p>Create a query expression<\/p>\n<pre class=\"lang:default decode:true  \">QueryExpression query = new QueryExpression(\"sitemap\");\nquery.ColumnSet = new ColumnSet(\"sitemapxml\");\nquery.Criteria = new FilterExpression\n{\n      \tFilterOperator = LogicalOperator.Or,\n       Conditions =\n{\n       \tnew ConditionExpression(\"sitemapnameunique\", ConditionOperator.Null),\n              new ConditionExpression(\"sitemapnameunique\", ConditionOperator.In, arrofAppSiteMap)\n       }\n};\t\nEntityCollection sitemaps = _service.RetrieveMultiple(query);<\/pre>\n<p>This will give Default SiteMap as well as app specific site map (which are present in collection of array) in collection.<\/p>\n<blockquote><p>Note: new ConditionExpression(&#8220;sitemapnameunique&#8221;, ConditionOperator.Null) this is used to retrieve default SiteMap XML<\/p><\/blockquote>\n<h2><strong>Conclusion:<\/strong><\/h2>\n<p style=\"text-align: justify;\">To retrieve collection of SiteMap in single query, we can use QueryExpression, to retrieve specific SiteMap (based on name) use linq and to retrieve default SiteMap we can use FetchExpression.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/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>Introduction: We can edit Sitemap by using Microsoft Dynamic SiteMap Designer or SiteMap Editor using XrmToolBox. Whereas we can also update SiteMap programmatically, but before updating SiteMap we have to retrieve SiteMap XML programmatically. So in this blog, we will discuss about how to retrieve SiteMap XML programmatically. Recently, we came across below scenario, Where\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2018\/07\/how-to-retrieve-sitemap-xml-programmatically-in-dynamic-365\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":12526,"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":[1628,1629],"class_list":["post-12525","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","category-dynamics-365-v9-2","category-dynamics-crm","tag-sitemap-xml-dynamics-365","tag-sitemap-xml-dynamics-crm"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/12525","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=12525"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/12525\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/12526"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=12525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=12525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=12525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}