{"id":15387,"date":"2019-04-12T12:52:52","date_gmt":"2019-04-12T12:52:52","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=15387"},"modified":"2021-03-06T10:08:08","modified_gmt":"2021-03-06T10:08:08","slug":"easyrepro-open-record-using-grid-openrecord-in-dynamics-365-unified-interface","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2019\/04\/easyrepro-open-record-using-grid-openrecord-in-dynamics-365-unified-interface\/","title":{"rendered":"EasyRepro \u2013 Open record using Grid.OpenRecord() in Dynamics 365 Unified Interface"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p>EasyRepro is a framework which is used to automate UI testing for dynamics customers Projects.<\/p>\n<h2><strong>Problem<\/strong><\/h2>\n<p>Grid.OpenRecord() method is used for opening the record from home page. This method opens the record by clicking on the first available anchor tag in the list of records, which makes it necessary to have the first column as primary name field of the entity.<\/p>\n<p>Below code emphasize the same:<\/p>\n<h2><strong>Code<\/strong><\/h2>\n<p>internal BrowserCommandResult&lt;bool&gt; OpenRecord(int index, int thinkTime = Constants.DefaultThinkTime, bool checkRecord = false)<\/p>\n<p>{<\/p>\n<p>this.Browser.ThinkTime(thinkTime);<\/p>\n<p>return this.Execute(GetOptions($&#8221;Open Grid Record&#8221;), driver =&gt;<\/p>\n<p>{<\/p>\n<p>var currentindex = 0;<\/p>\n<p>var rows = driver.FindElements(By.ClassName(&#8220;wj-row&#8221;));<\/p>\n<p>\/\/TODO: The grid only has a small subset of records. Need to load them all<\/p>\n<p>foreach (var row in rows)<\/p>\n<p>{<\/p>\n<p>if (!string.IsNullOrEmpty(row.GetAttribute(&#8220;data-lp-id&#8221;)))<\/p>\n<p>{<\/p>\n<p>if (currentindex == index)<\/p>\n<p>{<\/p>\n<p>\/\/This is the piece of code that does the opening of the record<\/p>\n<p>var tag = checkrecord ? &#8220;div&#8221; : &#8220;a&#8221;;<\/p>\n<p>row.findelement(by.tagname(tag)).click();<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>currentindex++;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>driver.WaitForTransaction();<\/p>\n<p>return true;<\/p>\n<p>});<\/p>\n<p>}<\/p>\n<h2><strong>Scenario<\/strong><\/h2>\n<p>Suppose, we want to open the record from \u201cAll Opportunities\u201d view by using Grid.OpenRecord() method. Then, we need to have a solution that opens the record without finding an anchor tag. The current method searches for first anchor tag(link). And with topic name blank, the first anchor tag(link) is of account due to which account record is opened instead of opportunity.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-15389\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/04\/UCI-Dynamics-365-CRM.png\" alt=\"UCI Dynamics 365 CRM\" width=\"995\" height=\"399\" \/><\/p>\n<h2><strong>Solution<\/strong><\/h2>\n<p>We need to replace the logic of opening the record on the basis of clicking an anchor tag to look for a label and double click it.<\/p>\n<p>internal BrowserCommandResult&lt;bool&gt; OpenRecord(int index, int thinkTime = \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Constants.DefaultThinkTime, bool checkRecord = false)<\/p>\n<p>{<\/p>\n<p>this.Browser.ThinkTime(thinkTime);<\/p>\n<p>return this.Execute(GetOptions($&#8221;Open Grid Record&#8221;), driver =&gt;<\/p>\n<p>{<\/p>\n<p>var currentindex = 0;<\/p>\n<p>var rows = driver.FindElements(By.ClassName(&#8220;wj-row&#8221;));<\/p>\n<p>\/\/TODO: The grid only has a small subset of records. Need to load them all<\/p>\n<p>foreach (var row in rows)<\/p>\n<p>{<\/p>\n<p>if (!string.IsNullOrEmpty(row.GetAttribute(&#8220;data-lp-id&#8221;)))<\/p>\n<p>{<\/p>\n<p>if (currentindex == index)<\/p>\n<p>{<\/p>\n<p>\/\/Replacing it with the below piece solves the issue.<\/p>\n<p>var tag = checkRecord ? &#8220;div&#8221; : &#8220;label&#8221;;<\/p>\n<p>SeleniumExtensions.DoubleClick(driver, By.TagName(tag), true);<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>currentindex++;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>driver.WaitForTransaction();<\/p>\n<p>return true;<\/p>\n<p>});<\/p>\n<p>}<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>The above code will help you to open record without finding an anchor tag in Dynamics 365 Unified Interface.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-pack\/click-2-clone-microsoft-dynamics-crm-records\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-15332\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2019\/04\/click2clone.png\" alt=\"click2clone\" width=\"816\" height=\"204\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction EasyRepro is a framework which is used to automate UI testing for dynamics customers Projects. Problem Grid.OpenRecord() method is used for opening the record from home page. This method opens the record by clicking on the first available anchor tag in the list of records, which makes it necessary to have the first column\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2019\/04\/easyrepro-open-record-using-grid-openrecord-in-dynamics-365-unified-interface\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":18209,"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":[18,19,2192,59],"tags":[549,1741],"class_list":["post-15387","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365-v9-2","category-dynamics-crm","category-easyrepro","category-uci","tag-dynamics-365-crm-unified-interface","tag-uci-dynamics-365-crm"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/15387","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=15387"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/15387\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/18209"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=15387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=15387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=15387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}