Dynamics CRM Setting Lead name based on Existing Customer
From Logic Wiki
This is how you get firstname and lastname of the customer
http://himbap.com/blog/?p=1739
And this is the modified JS to bring address and other details
function ParentContactId_OnChange() {
if (Xrm.Page.getAttribute('parentcontactid') != null) {
var ContactId = Xrm.Page.getAttribute('parentcontactid').getValue()[0].id;
//utilize retrieveRecord method from REST library to get data based on contact id
SDK.REST.retrieveRecord(
ContactId,
'Contact',
"FirstName,LastName,Address1_Line1,Address1_Line2,Address1_Line3,Address1_City,Address1_PostalCode,Telephone1,EMailAddress1,MobilePhone",null,
function(contact) {
//once we have data fill name fields
Xrm.Page.getAttribute('firstname').setValue(contact.FirstName);
Xrm.Page.getAttribute('lastname').setValue(contact.LastName);
Xrm.Page.getAttribute('fullname').setValue(contact.FirstName + ' ' + contact.LastName);
Xrm.Page.getAttribute('address1_line1').setValue(contact.Address1_Line1);
Xrm.Page.getAttribute('address1_line2').setValue(contact.Address1_Line2);
Xrm.Page.getAttribute('address1_line3').setValue(contact.Address1_Line3);
Xrm.Page.getAttribute('address1_city').setValue(contact.Address1_City);
Xrm.Page.getAttribute('address1_postalcode').setValue(contact.Address1_PostalCode);
Xrm.Page.getAttribute('telephone1').setValue(contact.Telephone1);
Xrm.Page.getAttribute('mobilephone').setValue(contact.MobilePhone);
Xrm.Page.getAttribute('emailaddress1').setValue(contact.EMailAddress1);
},
function Error() {
alert('There is error in reading contact data');
});
}