{"id":26157,"date":"2020-12-28T13:36:48","date_gmt":"2020-12-28T13:36:48","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=26157"},"modified":"2021-03-06T09:10:05","modified_gmt":"2021-03-06T09:10:05","slug":"how-to-set-value-in-a-regarding-field-using-easyrepro-in-dynamics-crm","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/12\/how-to-set-value-in-a-regarding-field-using-easyrepro-in-dynamics-crm\/","title":{"rendered":"How to Set Value in A Regarding Field Using Easyrepro in Dynamics CRM"},"content":{"rendered":"<h1><strong>Introduction<\/strong><\/h1>\n<p style=\"text-align: justify;\">Using Easyrepro we can perform UI Automation testing in Dynamics CRM by setting values in fields of different datatypes.<\/p>\n<p style=\"text-align: justify;\">Recently while working with Easyrepro we wanted to set a value in the Regarding field of the Email record.<\/p>\n<p style=\"text-align: justify;\">However, the code below which is used to set the value in a lookup field doesn\u2019t seem to work for the Regarding field.<\/p>\n<p><strong>xrmApp.Entity.SetValue(new LookupItem { Name = &#8220;regardingobjectid&#8221;, Value = &#8220;Abraham McCormick&#8221; });<\/strong><\/p>\n<p style=\"text-align: justify;\"><strong>Note:<\/strong> In our scenario, <strong>Abraham McCormick<\/strong> is the name of the contact record regarding which we want to create an email.<\/p>\n<p style=\"text-align: justify;\">Now, let us understand our piece of code.<\/p>\n<p><strong>Step 1:<\/strong><\/p>\n<p style=\"text-align: justify;\">Staying on the current window is necessary to find the elements. The below code will make sure that we are on the current window where the field is present.<\/p>\n<p><em>var <\/em><em>xrmBrowser = client.Browser;<\/em><\/p>\n<p><em>var<\/em><em> win = xrmBrowser.Driver.SwitchTo().Window(xrmBrowser.Driver.CurrentWindowHandle);<\/em><\/p>\n<p><em>xrmApp.ThinkTime(5000);<\/em><\/p>\n<p><strong>Step 2:<\/strong><\/p>\n<p style=\"text-align: justify;\">First, we need to validate if we have the correct Regarding element for access.<\/p>\n<p>To get the Regarding field element you can quickly check in the dev tool as below<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-1.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26158 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-1.png\" alt=\"Regarding field \" width=\"1152\" height=\"538\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-1.png 1152w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-1-300x140.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-1-768x359.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-1-1024x478.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-1-660x308.png 660w\" sizes=\"(max-width: 1152px) 100vw, 1152px\" \/><\/a><\/p>\n<p>And then use the below <strong><em>if<\/em><\/strong> statement to validate the existence of the element.<\/p>\n<p><em>if<\/em><em> (win.HasElement(<\/em><em>By<\/em><em>.XPath(<\/em><em>&#8220;.\/\/input[@aria-label=&#8217;Regarding, Lookup&#8217;]&#8221;<\/em><em>)))<\/em><\/p>\n<p><em>{<\/em><\/p>\n<p><em>}<\/em><\/p>\n<p><strong>Step 3:<\/strong><\/p>\n<p style=\"text-align: justify;\">Once the existence of the Regarding field element is validated in Step 2, find the clickable element for the same using the below piece of code which needs to be added inside the if statement from Step 2.<\/p>\n<p><em>\/\/Find the clickable element of the Regarding field<\/em><\/p>\n<p><em>var <\/em><em>regardingElements = win.FindClickable(<\/em><em>By<\/em><em>.XPath(<\/em><em>&#8220;.\/\/input[@aria-label=&#8217;Regarding, Lookup&#8217;]&#8221;<\/em><em>));<\/em><\/p>\n<p><strong>Step 4:<\/strong><\/p>\n<p style=\"text-align: justify;\">Now once the element is found in Step 3 you just need to access it by clicking on it and then pass the record name which you want to set as regarding.<\/p>\n<p><em>xrmApp.ThinkTime(5000);<\/em><\/p>\n<p><em>regardingElements.Click();<\/em><\/p>\n<p><em>regardingElements.SendKeys(<\/em>recordName<em>);<\/em><em>\/\/Set the name of the record which you want to set<\/em><\/p>\n<p><em>xrmApp.ThinkTime(5000);<\/em><\/p>\n<p><strong>Step 5:<\/strong><\/p>\n<p style=\"text-align: justify;\">Once the name of the record is passed in the Regarding field from the previous step you will see a drop down with the actual record in it as shown in the screenshot below.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-2.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26159 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-2.png\" alt=\"How to set value in aregarding field using Easyrepro in Dynamics CRM\" width=\"1150\" height=\"806\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-2.png 1150w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-2-300x210.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-2-768x538.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-2-1024x718.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-2-660x463.png 660w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-2-200x140.png 200w\" sizes=\"(max-width: 1150px) 100vw, 1150px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">And the below lines of code select the respective record from the list.<\/p>\n<p style=\"text-align: justify;\"><strong>Note:<\/strong> There could be chances of being more than 1 record with the same name. So to select the correct one from the list you will have to use the number to select the right element as can be seen in the code below. The number is optional to set the regarding field. If not provided, then it will choose the record at the 0th position by default.<\/p>\n<p><em>win = xrmBrowser.Driver.SwitchTo().Window(xrmBrowser.Driver.CurrentWindowHandle);<\/em><\/p>\n<p><em>xrmApp.ThinkTime(5000);<\/em><\/p>\n<p><em>\/\/Find the element in the dropdown for which the name was passed<\/em><\/p>\n<p><em>if<\/em><em> (win.HasElement(<\/em><em>By<\/em><em>.XPath(<\/em><em>&#8220;\/\/li[contains(@aria-label,<\/em>&#8216;&#8221; + <em>recordName<\/em> + &#8220;&#8216;<em>)]&#8221;<\/em><em>)))<\/em><\/p>\n<p><em>{<\/em><\/p>\n<p><em>var records = win.FindElements(By.XPath(&#8220;\/\/li[contains(@aria-label,'&#8221; + recordName + &#8220;&#8216;)]&#8221;));<\/em><\/p>\n<p><em>if (records.Count&gt; number)<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 {<\/em><\/p>\n<p><em>records[number].Click();<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 }<\/em><\/p>\n<p><em>elseif (records.Count&gt;0)<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 {<\/em><\/p>\n<p><em>records[0].Click();<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 }<\/em><\/p>\n<p><em>xrmApp.ThinkTime(5000);<\/em><\/p>\n<p><em>}<\/em><\/p>\n<p>And as can be seen from the screenshot below the value gets set in the Regarding field.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-3.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26160 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-3.png\" alt=\"How to set value in aregarding field using Easyrepro in Dynamics CRM\" width=\"1121\" height=\"148\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-3.png 1121w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-3-300x40.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-3-768x101.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-3-1024x135.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/How-to-Set-Value-in-Aregarding-Field-Using-Easyrepro-in-Dynamics-CRM-3-660x87.png 660w\" sizes=\"(max-width: 1121px) 100vw, 1121px\" \/><\/a><\/p>\n<p>We have created a generic function named SetRegarding with 4 parameters as below, which can be seen at the end of the blog post.<br \/>\n\u2022 <strong>XrmApp xrmApp-<\/strong> This will carry forward the object of <strong>XrmApp<\/strong> from the test method.(Required)<br \/>\n\u2022 <strong>WebClient client &#8211;<\/strong> This will carry forward the object of <strong>WebClient<\/strong> from the test method. (Required)<br \/>\n\u2022<strong> string recordName-<\/strong>This will hold the name of the record which we want to set as regarding. In our scenario <strong>Abraham McCormick<\/strong> is the name of the record.(Required)<br \/>\n\u2022 <strong>int number &#8211;<\/strong> This will hold a numeric value which shall be used to select a record if there are more than 1 record with the same name. (Optional)<\/p>\n<p style=\"text-align: justify;\">So in the test method after you have set the other attribute values, use our function to set the value in the <strong>Regarding<\/strong> field as below.<\/p>\n<p style=\"text-align: justify;\"><strong>SetRegarding(xrmApp, client, &#8220;Abraham McCormick&#8221;, 0);<\/strong><\/p>\n<p>Given below is the generic function to set the value of the Regarding field while creating an Email record:<\/p>\n<p><em>\/\/\/&lt;summary&gt;<\/em><\/p>\n<p><em>\/\/\/<\/em><em> Generic function to set the regarding field<\/em><\/p>\n<p><em>\/\/\/&lt;\/summary&gt;<\/em><\/p>\n<p><em>\/\/\/&lt;param name=&#8221;<\/em><em>xrmApp<\/em><em>&#8220;&gt;<\/em><em>This will carry forward the object of XrmApp from the test method.<\/em><em>&lt;\/param&gt;<\/em><\/p>\n<p><em>\/\/\/&lt;param name=&#8221;<\/em><em>client<\/em><em>&#8220;&gt;<\/em><em>This will carry forward the object of WebClient from the test method.<\/em><em>&lt;\/param&gt;<\/em><\/p>\n<p><em>\/\/\/&lt;param name=&#8221;<\/em><em>recordName<\/em><em>&#8220;&gt;<\/em><em>This will hold the name of the record which we want to set as regarding.<\/em><em>&lt;\/param&gt;<\/em><\/p>\n<p><em>\/\/\/&lt;param name=&#8221;<\/em><em>number<\/em><em>&#8220;&gt;<\/em><em>This will hold a numeric value which shall be used to select a record if there are more than 1 records with same name. In case no value is passed by default\u00a0 the record at the 0<sup>th<\/sup> position will get set<\/em><em>&lt;\/param&gt;<\/em><\/p>\n<p><em>public void <\/em><em>SetRegarding(<\/em><em>XrmApp <\/em><em>xrmApp, <\/em><em>WebClient<\/em><em> client, <\/em><em>string <\/em><em>recordName, <\/em><em>int<\/em><em> number = 0)<\/em><\/p>\n<p><em>{<\/em><\/p>\n<p><em>\/\/Local Variables<\/em><\/p>\n<p><em>string <\/em><em>functionName = <\/em><em>&#8220;setRegarding&#8221;<\/em><em>;<\/em><\/p>\n<p><em>try<\/em><\/p>\n<p><em>\u00a0 {<\/em><\/p>\n<p><em>var <\/em><em>xrmBrowser = client.Browser;<\/em><\/p>\n<p><em>var<\/em><em> win = xrmBrowser.Driver.SwitchTo().Window(xrmBrowser.Driver.CurrentWindowHandle);<\/em><\/p>\n<p><em>xrmApp.ThinkTime(5000);<\/em><\/p>\n<p><em>if<\/em><em> (win.HasElement(<\/em><em>By<\/em><em>.XPath(<\/em><em>&#8220;.\/\/input[@aria-label=&#8217;Regarding, Lookup&#8217;]&#8221;<\/em><em>)))<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0 {<\/em><\/p>\n<p><em>var <\/em><em>regardingElements = win.FindClickable(<\/em><em>By<\/em><em>.XPath(<\/em><em>&#8220;.\/\/input[@aria-label=&#8217;Regarding, Lookup&#8217;]&#8221;<\/em><em>));<\/em><\/p>\n<p><em>xrmApp.ThinkTime(5000);<\/em><\/p>\n<p><em>regardingElements.Click();\u00a0 <\/em><\/p>\n<p><em>regardingElements.SendKeys(recordName);<\/em> \/\/Set the name of the record which you want to set<\/p>\n<p><em>xrmApp.ThinkTime(5000);<\/em><\/p>\n<p><em>win = xrmBrowser.Driver.SwitchTo().Window(xrmBrowser.Driver.CurrentWindowHandle);<\/em><\/p>\n<p><em>xrmApp.ThinkTime(5000);<\/em><\/p>\n<p><em>if<\/em><em> (win.HasElement(<\/em><em>By<\/em><em>.XPath(<\/em><em>&#8220;\/\/li[contains(@aria-label,'&#8221;<\/em><em> + recordName + <\/em><em>&#8220;&#8216;)]&#8221;<\/em><em>)))<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/em><\/p>\n<p><em>var<\/em><em> records = win.FindElements(<\/em><em>By<\/em><em>.XPath(<\/em><em>&#8220;\/\/li[contains(@aria-label,'&#8221;<\/em><em> + recordName + <\/em><em>&#8220;&#8216;)]&#8221;<\/em><em>));<\/em><\/p>\n<p><em>if<\/em><em> (records.Count&gt; number)<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/em><\/p>\n<p><em>records[number].Click();<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/em><\/p>\n<p><em>elseif<\/em><em> (records.Count&gt; 0)<\/em><\/p>\n<p><em>{<\/em><\/p>\n<p><em>records[0].Click();<\/em><\/p>\n<p><em>}<\/em><\/p>\n<p><em>xrmApp.ThinkTime(5000);<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/em><\/p>\n<p><em>\u00a0\u00a0\u00a0 }<\/em><\/p>\n<p><em>\u00a0 }<\/em><\/p>\n<p><em>catch<\/em><em> (<\/em><em>Exception<\/em><em> ex)<\/em><\/p>\n<p><em>\u00a0 {<\/em><\/p>\n<p><em>throw new <\/em><em>Exception<\/em><em>(functionName + <\/em><em>&#8221; :: &#8220;<\/em><em> + ex.Message);<\/em><\/p>\n<p><em>\u00a0 }<\/em><\/p>\n<p><em>}<\/em><\/p>\n<p>Conclusion<\/p>\n<p>In this way set value in a regarding field using Easyrepro in Dynamics CRM.<\/p>\n<p><a href=\"https:\/\/www.maplytics.com\/map-optimize-route-dynamics-crm\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26161 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/7.png\" alt=\"\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/7.png 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/7-300x75.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/7-768x192.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/12\/7-660x165.png 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Using Easyrepro we can perform UI Automation testing in Dynamics CRM by setting values in fields of different datatypes. Recently while working with Easyrepro we wanted to set a value in the Regarding field of the Email record. However, the code below which is used to set the value in a lookup field doesn\u2019t\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/12\/how-to-set-value-in-a-regarding-field-using-easyrepro-in-dynamics-crm\/\">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,19,2192],"tags":[592,2104,2105],"class_list":["post-26157","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-dynamics-crm","category-easyrepro","tag-dynamics-crm","tag-easyrepro","tag-regarding-field"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/26157","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=26157"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/26157\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=26157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=26157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=26157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}