{"id":25999,"date":"2020-12-11T12:30:11","date_gmt":"2020-12-11T12:30:11","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=25999"},"modified":"2021-03-06T10:11:35","modified_gmt":"2021-03-06T10:11:35","slug":"set-the-subject-hierarchy-field-on-products-cases-sales-literature-and-articles-using-easypro","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/12\/set-the-subject-hierarchy-field-on-products-cases-sales-literature-and-articles-using-easypro\/","title":{"rendered":"Set the subject hierarchy field on Products, Cases, Sales Literature and Articles using Easypro"},"content":{"rendered":"<h1><b>Introduction<\/b><\/h1>\n<p style=\"text-align: justify;\">EasyRepro is an automated UI testing framework that helps developers perform unit testing on Dynamics 365 CRM. Even though it helps a lot for UI testing, still there are some shortcomings due to which we cannot perform certain actions on Dynamics 365 CRM.<\/p>\n<p style=\"text-align: justify;\">In this blog, we will be tackling one such issue of EasyRepro that have been mentioned <a href=\"https:\/\/github.com\/microsoft\/EasyRepro\/issues\/750\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. The issue is, the Subject field requires special handling, which is as of now not achievable at the time of writing this blog as is using EasyRepo Framework.<\/p>\n<p>To handle this special field, one can use the below code to set N-number of hierarchy.<\/p>\n<p>Code: &#8211;<\/p>\n<blockquote><p>\/\/\/ &lt;summary&gt;<\/p>\n<p>\/\/\/ Function to set value in Special Type of Subject hierarchy field in CRM<\/p>\n<p>\/\/\/ &lt;\/summary&gt;<\/p>\n<p>\/\/\/ &lt;param name=&#8221;fieldLogicalName&#8221;&gt;&lt;\/param&gt;<\/p>\n<p>\/\/\/ &lt;param name=&#8221;category&#8221;&gt;&lt;\/param&gt;<\/p>\n<p>\/\/\/ &lt;param name=&#8221;xrmApp&#8221;&gt;&lt;\/param&gt;<\/p>\n<p>\/\/\/ &lt;param name=&#8221;driver&#8221;&gt;&lt;\/param&gt;<\/p>\n<p>public void setSubjectField(string fieldLogicalName, string[] category, XrmApp xrmApp, IWebDriver driver) {<\/p>\n<p>\/\/Select and open dropdown Field<\/p>\n<p>var control = driver.LastWindow().FindElement(By.CssSelector(&#8220;*[id*='&#8221; + fieldLogicalName + &#8220;&#8216;] *[id*=&#8217;input&#8217;]&#8221;));<\/p>\n<p>control.Click();<\/p>\n<p>xrmApp.ThinkTime(2000);<\/p>\n<p>\/\/Parent Element<\/p>\n<p>var listOfOptions = driver.LastWindow().FindElements(By.CssSelector(&#8220;*[id*='&#8221; + fieldLogicalName + &#8220;&#8216;] li[id*=&#8217;tree-dropdown&#8217;]&#8221;));<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/Find teh first element<\/p>\n<p>IWebElement iwebelm = listOfOptions.FirstOrDefault(t =&gt; t.Text == category.FirstOrDefault());<\/p>\n<p>if (iwebelm == null) return;<\/p>\n<p>&nbsp;<\/p>\n<p>if (category.Length &lt;= 1) { \/*Select first element *\/ iwebelm.Click(); return; }<\/p>\n<p>\/\/Expand the parent element if need to select child element<\/p>\n<p>if (!Convert.ToBoolean(iwebelm.GetAttribute(&#8220;aria-expanded&#8221;)))<\/p>\n<p>{<\/p>\n<p>\/\/Expand the child hierarchy<\/p>\n<p>var caretDown = iwebelm.FindElement(By.CssSelector(&#8220;*[id*='&#8221; + fieldLogicalName + &#8220;&#8216;] *[id*=&#8217;tree-dropdown-icon&#8217;]&#8221;));<\/p>\n<p>if (caretDown != null)<\/p>\n<p>caretDown.Click();<\/p>\n<p>}<\/p>\n<p>for (int i = 1; i &lt; category.Length; i++)<\/p>\n<p>{<\/p>\n<p>xrmApp.ThinkTime(500);<\/p>\n<p>var listOfCategory = driver.LastWindow().FindElements(By.CssSelector(&#8220;*[id*='&#8221; + fieldLogicalName + &#8220;&#8216;] li[id*=&#8217;tree-dropdown-sublist&#8217;]&#8221;));<\/p>\n<p>&nbsp;<\/p>\n<p>var subCategoyList = listOfCategory[(listOfCategory.Count &gt; 1) ? i &#8211; 1 : 0].FindElements(By.TagName(&#8220;li&#8221;));<\/p>\n<p>var subCategoryElement = subCategoyList.FirstOrDefault(t =&gt; t.FindElement(By.CssSelector(&#8220;label&#8221;)).Text == category[i]);<\/p>\n<p>if (i != category.Length &#8211; 1 &amp;&amp; subCategoryElement != null)<\/p>\n<p>{<\/p>\n<p>\/\/expand<\/p>\n<p>var caretElement = subCategoryElement.FindElement(By.CssSelector(&#8220;span&#8221;));<\/p>\n<p>if (caretElement != null)<\/p>\n<p>caretElement.Click();<\/p>\n<p>&nbsp;<\/p>\n<p>}<\/p>\n<p>else if (subCategoryElement != null)<\/p>\n<p>{<\/p>\n<p>\/\/Select child element<\/p>\n<p>xrmApp.ThinkTime(1000);<\/p>\n<p>subCategoryElement.FindElement(By.CssSelector(&#8220;label&#8221;)).Click();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p><\/blockquote>\n<h2>Working<\/h2>\n<p style=\"text-align: justify;\">Suppose we have a requirement of setting up <strong>Product Delivery<\/strong> in the Subject tree which is a child of <strong>Delivery<\/strong> which is further inside the <strong>Service <\/strong>node.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-1.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26000 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-1.png\" alt=\"SET THE SUBJECT HIERARCHY FIELD ON PRODUCTS, CASES, SALES LITERATURE, AND ARTICLES USING EASYREPRO\" width=\"1075\" height=\"509\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-1.png 1075w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-1-300x142.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-1-768x364.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-1-1024x485.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-1-660x313.png 660w\" sizes=\"(max-width: 1075px) 100vw, 1075px\" \/><\/a><\/p>\n<p>In the code we need to pass the parameter for the above function as<\/p>\n<ul>\n<li>FieldName<\/li>\n<li>String Array Containing list of subject hierarchy (which in the above case would be Service, Delivery, Product Delivery)<\/li>\n<li>XrmApp (XrmApp object)<\/li>\n<li>Driver (Client Driver)<\/li>\n<\/ul>\n<p>e.g.<\/p>\n<p>xrmApp.CommandBar.ClickCommand(&#8220;New Case&#8221;);<\/p>\n<p>xrmApp.ThinkTime(200);<\/p>\n<p>setSubjectField(&#8220;subjectid&#8221;, new string[] { &#8220;Service&#8221;, &#8220;Delivery&#8221;, &#8220;Product Delivery&#8221; }, xrmApp, xrmBrowser.Driver);<\/p>\n<h2>Result<\/h2>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-2.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26001 size-full\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-2.png\" alt=\"SET THE SUBJECT HIERARCHY FIELD ON PRODUCTS, CASES, SALES LITERATURE, AND ARTICLES USING EASYREPRO\" width=\"1019\" height=\"648\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-2.png 1019w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-2-300x191.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-2-768x488.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/SET-THE-SUBJECT-HIERARCHY-FIELD-ON-PRODUCTS-CASES-SALES-LITERATURE-AND-ARTICLES-USING-EASYREPRO-2-660x420.png 660w\" sizes=\"(max-width: 1019px) 100vw, 1019px\" \/><\/a><\/p>\n<h1>Conclusion<\/h1>\n<p>Using the above code we can set the Subject field present on products, cases, sales literature, and article.<\/p>\n<p><a href=\"https:\/\/maplytics.com\/blog\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26002 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/1-1.jpg\" alt=\"\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/1-1.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/1-1-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/1-1-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/1-1-660x165.jpg 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction EasyRepro is an automated UI testing framework that helps developers perform unit testing on Dynamics 365 CRM. Even though it helps a lot for UI testing, still there are some shortcomings due to which we cannot perform certain actions on Dynamics 365 CRM. In this blog, we will be tackling one such issue of\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/12\/set-the-subject-hierarchy-field-on-products-cases-sales-literature-and-articles-using-easypro\/\">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,18,19,24,2192],"tags":[545,592,2096,2097],"class_list":["post-25999","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-dynamics-365-v9-2","category-dynamics-crm","category-dynamics-crm-2016","category-easyrepro","tag-dynamics-365-crm","tag-dynamics-crm","tag-easypro","tag-easypro-dynamics-365-crm"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/25999","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=25999"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/25999\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=25999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=25999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=25999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}