{"id":31696,"date":"2022-05-30T16:10:29","date_gmt":"2022-05-30T10:40:29","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=31696"},"modified":"2022-05-30T16:10:29","modified_gmt":"2022-05-30T10:40:29","slug":"how-to-retrieve-set-lookup-record-information-using-addonlookuptagclick-function","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2022\/05\/how-to-retrieve-set-lookup-record-information-using-addonlookuptagclick-function\/","title":{"rendered":"How to retrieve set lookup record information using addOnLookupTagClick() function"},"content":{"rendered":"<h2><strong>Introduction:<\/strong><\/h2>\n<p>In this blog, we will check how can we get the entity record information that is set in lookup control without losing the main entity form context.<\/p>\n<h2><strong>Problem<\/strong>:<\/h2>\n<p>While we are on a record form of an entity, if we want to get the information about the record that is set in a lookup control within that record form, then we need to click on the record link on lookup control. When we click on the link of the lookup control, the respective set record gets opened in the same window and we lose the current entity from context. Let us take an example, suppose we open an Opportunity entity form that has an Account entity lookup control. We want to see the details about the respective account record that is set in lookup control, but the problem here is that when we click on lookup control we are redirected to the Account entity form of the respective set account record as shown in the below screenshot. In this case, we lose the main entity form context i.e Opportunity entity form.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31699\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/1addOnLookupTagClick.jpeg\" alt=\"addOnLookupTagClick\" width=\"1363\" height=\"557\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/1addOnLookupTagClick.jpeg 1363w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/1addOnLookupTagClick-300x123.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/1addOnLookupTagClick-1024x418.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/1addOnLookupTagClick-768x314.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/1addOnLookupTagClick-660x270.jpeg 660w\" sizes=\"(max-width: 1363px) 100vw, 1363px\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31698\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/2addOnLookupTagClick.jpeg\" alt=\"addOnLookupTagClick\" width=\"1356\" height=\"558\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/2addOnLookupTagClick.jpeg 1356w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/2addOnLookupTagClick-300x123.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/2addOnLookupTagClick-1024x421.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/2addOnLookupTagClick-768x316.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/2addOnLookupTagClick-660x272.jpeg 660w\" sizes=\"(max-width: 1356px) 100vw, 1356px\" \/><\/p>\n<h2><strong>Solution<\/strong>:<\/h2>\n<p>To overcome the context loss problem, Microsoft introduced one of the functions called <strong>addOnLookupTagClick() <\/strong>where we can get the information about the record which is set by the lookup control. This function will return the following parameters as follows:<\/p>\n<p><strong>1. id<\/strong> &#8211; It is a string type parameter that indicates the GUID of the record which is set in lookup control.<\/p>\n<p><strong>2. fieldName<\/strong> &#8211; It is a string type of parameter which contains the logical name of lookup control.<\/p>\n<p><strong>3. entityType<\/strong> &#8211; This parameter is also string type which indicates the entity logical name of the lookup control entity.<\/p>\n<p><strong>4. name<\/strong> &#8211; It indicates the name value of the record which is set in lookup control.<\/p>\n<p>Please find the below source code which helps us to execute the <strong>addOnLookupTagClick() <\/strong>function to retrieve the information of the lookup record. When we click on lookup record, a CRM dialogue box will be opened which includes all the information related to the selected record as shown in the screenshot below.<\/p>\n<p><strong><em><u>Note: Below source code is registered on a load of Opportunity entity form.\u00a0<\/u><\/em><\/strong><\/p>\n<pre class=\"lang:css gutter:true start:1\">\r\nfunction onLoadFunction (executionContext) {\r\n\r\n\/\/retrive the form context\r\n\r\nvar formContext = executionContext.getFormContext();\r\n\r\n\/\/Using addOnLookupTagClick Client API.\r\n\r\nformContext.getControl(\"parentaccountid\").addOnLookupTagClick(function(e){\r\n\r\n\/\/retrict the lookup link click envent\r\n\r\ne.getEventArgs().preventDefault();\r\n\r\n\/\/get record details from addOnLookupTagClick success funtion\r\n\r\nvar currentLookUpRecord = null;\r\n\r\nif(e.getEventArgs()._tagValue !=null &amp;&amp; e.getEventArgs()._tagValue != undefined){\r\n\r\ncurrentLookUpRecord = e.getEventArgs()._tagValue;\r\n\r\n}\r\n\r\n\/\/display lookup record value using alert dialouge funtion\r\n\r\nvar message = { confirmButtonLabel: \"OK\", text: \"Name:\"+ currentLookUpRecord.name+\"\\nId:\"+currentLookUpRecord.id+\"\\nfieldName:\"+currentLookUpRecord.fieldName+\"\\nentityType:\"+currentLookUpRecord.entityType};\r\n\r\nvar alertOptions = { height: 200, width: 280 };\r\n\r\nXrm.Navigation.openAlertDialog(message, alertOptions).then(\r\n\r\nfunction success(result) {\r\n\r\n},\r\n\r\nfunction (error) {\r\n\r\nconsole.log(error.message);\r\n\r\n}\r\n\r\n);\r\n\r\n});\r\n\r\n}<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31697\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/3addOnLookupTagClick.jpeg\" alt=\"addOnLookupTagClick\" width=\"1365\" height=\"631\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/3addOnLookupTagClick.jpeg 1365w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/3addOnLookupTagClick-300x139.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/3addOnLookupTagClick-1024x473.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/3addOnLookupTagClick-768x355.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/3addOnLookupTagClick-660x305.jpeg 660w\" sizes=\"(max-width: 1365px) 100vw, 1365px\" \/><\/p>\n<h2><strong>Conclusion<\/strong>:<\/h2>\n<p>With the help of <strong>addOnLookupTagClick() <\/strong>we can easily get the information of the respective record that is set in the lookup control without losing the main entity from context.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/add-manage-schedule-notifications-alerts-4-dynamics-365-crm\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone  wp-image-31700\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/A4D.jpg\" alt=\"\" width=\"852\" height=\"213\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/A4D.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/A4D-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/A4D-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/05\/A4D-660x165.jpg 660w\" sizes=\"(max-width: 852px) 100vw, 852px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: In this blog, we will check how can we get the entity record information that is set in lookup control without losing the main entity form context. Problem: While we are on a record form of an entity, if we want to get the information about the record that is set in a lookup\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2022\/05\/how-to-retrieve-set-lookup-record-information-using-addonlookuptagclick-function\/\">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,2361],"tags":[2608],"class_list":["post-31696","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-dynamics-365-v9-2","category-technical","tag-addonlookuptagclick-function"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/31696","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=31696"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/31696\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=31696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=31696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=31696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}