{"id":1739,"date":"2015-10-14T09:04:35","date_gmt":"2015-10-14T09:04:35","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=1739"},"modified":"2015-11-30T10:29:23","modified_gmt":"2015-11-30T10:29:23","slug":"setting-lead-name-based-on-existing-customer","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=1739","title":{"rendered":"Setting Lead name based on Existing Customer"},"content":{"rendered":"<p>Do you feel it annoying to enter <strong>First Name<\/strong> and <strong>Last Name<\/strong> in lead\u00a0even <strong>Existing Contact <\/strong>is selected already??, if yes then this post will help you to auto populate these fields as soon as <strong>Existing Contact<\/strong> is selected. Lead entity contains fullname which is primary field (key attribute). It\u00a0is combination for First and Last name. These fields is used to create contact record if <strong>Existing Contact<\/strong> lookup is not selected under lead, so based on default process when lead is qualified it will create a contact record with the value of these fields (<em>We can write a plug-in to stop create contact record if required<\/em>)<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1741 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead1-300x136.png\" alt=\"Lead1\" width=\"300\" height=\"136\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead1-300x136.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead1-624x283.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead1.png 696w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>Requirement<\/strong>:\u00a0 We need to fill First Name and Last Name based on the Existing Contact lookup.<\/p>\n<p><strong>Solution<\/strong>: Existing Contact field is placed on the business process flow and logical name of the field is parentcontactid. We can write a quick script with the help of OData endpoints to get selected contact firstname and lastname and set it on the lead record. To call our script we need to place this field on lead form first. Following are the steps to implement this solution:<\/p>\n<ul>\n<li>Create custom solution or open default solution by navigating <strong>Settings -&gt; Customizations-&gt; Customize <\/strong>the system<\/li>\n<li>Add a new script web resource and upload <strong>SDK.REST.js <\/strong>library like below, this library comes with CRM SDK, you can find it under <em>\\SampleCode\\JS\\RESTEndpoint\\JavaScriptRESTDataOperations\\JavaScriptRESTDataOperations\\Scripts<\/em><\/li>\n<\/ul>\n<p><strong>Note<\/strong>: If you have not downloaded CRM SDK then first download it from <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=44567\">here<\/a> and then extract it.<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead4.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1744 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead4-300x165.png\" alt=\"Lead4\" width=\"300\" height=\"165\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead4-300x165.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead4-624x344.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead4.png 648w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<ul>\n<li>Create another Java Script web resource and let\u2019s name it <strong>Lead.js, <\/strong>we need to place following code under <strong>Text Editor<\/strong>:<\/li>\n<\/ul>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction ParentContactId_OnChange() {\r\n\tif (Xrm.Page.getAttribute('parentcontactid') != null) {\r\n\r\n\t\tvar ContactId = Xrm.Page.getAttribute('parentcontactid').getValue()[0].id;\r\n\r\n\t\t\/\/utilize retrieveRecord method from REST library to get data based on contact id\r\n\r\n\t\tSDK.REST.retrieveRecord(\r\n\r\n\t\tContactId,\r\n\r\n\t\t\t'Contact',\r\n\r\n\t\tnull, null,\r\n\r\n\t\tfunction(contact) {\r\n\r\n\t\t\t\/\/once we have data fill name fields\r\n\r\n\t\t\tXrm.Page.getAttribute('firstname').setValue(contact.FirstName);\r\n\r\n\t\t\tXrm.Page.getAttribute('lastname').setValue(contact.LastName);\r\n\r\n\t\t\tXrm.Page.getAttribute('fullname').setValue(contact.FirstName + ' ' + contact.LastName);\r\n\r\n\t\t},\r\n\r\n\t\tfunction Error() {\r\n\t\t\talert('There is error in reading contact data');\r\n\t\t});\r\n\r\n\t}\r\n}\r\n<\/pre>\n<ul>\n<li>Save and close web resource<\/li>\n<li>Double click on Lead form to open form editor by navigating <strong>Lead-&gt;Forms-&gt;Lead<\/strong>, under your solution, and drag and drop\u00a0<strong>Parent Contact for lead<\/strong>\u00a0on lead form from <strong>Field Explorer<\/strong><\/li>\n<\/ul>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead2.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1742 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead2-300x129.png\" alt=\"Lead2\" width=\"300\" height=\"129\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead2-300x129.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead2.png 464w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<ul>\n<li>Double click on this field now and add our both web resources and bind on change event using following steps in below screen:<\/li>\n<\/ul>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead3.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1743 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead3-300x267.png\" alt=\"Lead3\" width=\"300\" height=\"267\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead3-300x267.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead3.png 490w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<ul>\n<li>Click on Display tab and uncheck following option, to hide our lookup field from lead form.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead5.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-1745 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead5.png\" alt=\"Lead5\" width=\"250\" height=\"83\" \/><\/a><\/p>\n<ul>\n<li>Save and Clos form.<\/li>\n<li>Click on <strong>Publish All Customizations<\/strong> to publish all the changes.<\/li>\n<\/ul>\n<p>Now when we will select Existing Contact in lead\u00a0it will auto populate <strong>Name<\/strong> field.<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead6.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1746 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead6-300x201.png\" alt=\"Lead6\" width=\"300\" height=\"201\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead6-300x201.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2015\/10\/Lead6.png 344w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you feel it annoying to enter First Name and Last Name in lead\u00a0even Existing Contact is selected already??, if yes then this post will help you to auto populate these fields as soon as Existing Contact is selected. Lead entity contains fullname which is primary field (key attribute). It\u00a0is combination for First and Last name. These fields is used&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=1739\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,1],"tags":[229,231,230],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1739"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1739"}],"version-history":[{"count":6,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1739\/revisions"}],"predecessor-version":[{"id":1889,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1739\/revisions\/1889"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}