Hi,
I have created a custom entity as "Study customer requirement" and on the lead entity have created a lookup to custom entity. In the custom entity there are 2 fields customer and contacts which is also there on the lead page.
Now on the lead page our regular practice is we select customer and contacts and after saving lead, clicking on Study Customer requirement lookup and select new. Now when new page comes it has to pick customer and contact from the lead page from where we start.
I tried with WF update records but it is not syncing the fields.
Pl help.
*This post is locked for comments
Thanks a lot Ravi, Code works perfectly.
Also, you need to use "leadContact[0] != null" check only for lookup fields. If the field is simple then you don't need this check.
Hi,
This should work provided the schema name on your lead record is "new_existingcustomer" and on you custom entity is "new_customer" and both are of same data type.
Hope this helps.
Thanks a lot Ravi,
Your updated code works perfectly.
Just wanted to know if need to add 1 more field, i have modified the same code, can i use like this ?
function getleadDetails() {
if (parent.window.parent.opener != null) {
var leadContact = parent.window.parent.opener.Xrm.Page.getAttribute("new_existingcontact").getValue();
var leadCustomer = parent.window.parent.opener.Xrm.Page.getAttribute("new_existingcustomer").getValue();
if (leadContact != null && leadContact[0] != null) {
Xrm.Page.getAttribute("new_contact").setValue(leadContact);
}
if (leadCustomer != null && leadContact[0] != null) {
Xrm.Page.getAttribute("new_customer").setValue(leadContact);
}
}
Try with this:
function getleadDetails() {
if (parent.window.parent.opener != null) {
var leadContact = parent.window.parent.opener.Xrm.Page.getAttribute("parentcontactid").getValue();
if (leadContact != null && leadContact[0] != null) {
Xrm.Page.getAttribute("new_contact").setValue(leadContact);
}
}
}
Yes, your understanding is correct. We need to put some check there so that it run's only when it is opened from the lead form.
Hi Ravi,
Thanks for the code.
First it works when opening new 'Study customer requirement" also picks contact but issue here is after saving the record when opening back getting error.
TypeError: Cannot read property 'Xrm' of null
at getleadDetails (crm/.../new_leadcontactsync_toappstudy)
at eval (eval at RunHandlerInternal (crm/.../ClientApiWrapper.aspx), <anonymous>:1:1)
at RunHandlerInternal (crm/.../ClientApiWrapper.aspx)
at RunHandlers (crm/.../ClientApiWrapper.aspx)
at OnScriptTagLoaded (crm/.../ClientApiWrapper.aspx)
at crm/.../ClientApiWrapper.aspx
I believe it is running each time when saved records get open?
Hi Syed,
You can register the below method on load of your custom entity. This method first retrieves the contact from lead and then on next statement sets that contact to your custom entity contact lookup. You need check & update the schema name.
=========
function getleadDetails() {
var leadContact = parent.window.parent.opener.Xrm.Page.getAttribute("parentcontactid").getValue();
if (leadContact != null && leadContact[0] != null) {
Xrm.Page.getAttribute("new_contact").setValue(leadContact);
}
}
=============
Hope this helps.
Hi Ravi,
Sorry i am not good in coding, could you please share complete Js.
Regards
Faisal
Just did a quick try. You can access lead record field using window.opener.
window.opener.Xrm.Page.data.entity.getId()
So, you can add a mthoed on the load of your custom entity and then retrieve the fields from lead as above and set it to the custom entity fields in the normal ways i.e. Xrm.Page.getAttribute(<SchemaName>).setValue(window.opener.Xrm.Page.getAttribute(<SchemaName>).getValue());
Hope this helps.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156