In my previous blogpost I described how to use XRM Service Toolkit in Dynamics CRM (2011 / 2013 / 2015 and 2016).
Today I am going to show how to retrieve parent account information onChange event of account lookup on Contact form.
Remember! Don’t forget to add XRMServiceToolkit library in form properties.
Now, from following code snippet you need to add getParentAccountInfo at onChange event of Parent Account field on contact field
function getParentAccountInfo(accountLookup)
{
try{
var accountID = Xrm.Page.getAttribute(accountLookup).getValue()[0].id;
var cols = ["emailaddress1","telephone1"];
var retrievedAccount = XrmServiceToolkit.Soap.Retrieve("contact", contactID, cols);
var emailAddress = Xrm.Page.getAttribute("emailaddress1");
var telePhone = Xrm.Page.getAttribute("telephone1");
var v_emailAddress = typeof retrievedAccount.attributes["emailaddress1"] === 'undefined'?'':
retrievedAccount.attributes["emailaddress1"].value;
var v_telephone = typeof retrievedAccount.attributes["telephone1"] === 'undefined'?'':
retrievedAccount.attributes["telephone1"].value;
emailAddress.setValue(v_emailAddress);
telePhone.setValue(v_telephone);
}
catch(e){
alert("Error Occured: "+e.Message);
}
}
Enjoy!
No comments:
Post a Comment