On my Contact form I have a look up to a custom Details Entity.
When the New option is selected, a Quick Create Form opens up for a user to input additional details about the new contact.
The Details form has a name field that I would like to populate with the Contact's full name and append "-Details"
Example. If the new contact that is being created has the name John Smith, I would like that name to prepopulate the Quick Create Details form onload as "John Smith-Details" in the name field.
What would the javascript code look like to capture the name from the contact form and use in the Quick Create Form?
*This post is locked for comments
Hello,
I would suggest resolve your issue in 2 steps.
1. Create a mapping between contact and your custom entity where fullname of contact is mapped with name field of your custom entity field.
2. Add onload event handler for Quick Create form that will execute following code:
var name = Xrm.Page.getAttribute("new_name").getValue();
name = (name == null ? "" : name) + "-Details";
Xrm.Page.getAttribute("new_name").setValue(name);
Hi Malo073,
What about doing the following so you do not need JavaScript :)
Approach
Create the Name field as a Calculated Field and set the value to CONCAT(new_contactid.fullname, "-Details") where the new_contactid is the contact entity that the Details is related to.
This will automatically set the value to what you are looking for, although it will not be able to be displayed on the "quick create" form but this is probably not an issue if it is truly a field that is set and can not be manually changed.
Verification
I set this up in my own environment and it worked perfectly. I also changed the first name of the contact and verified it displayed the updated value for the field on the Details entity and it did (which is expected since it is a calculated field) :)
Other Approaches (if you do not follow above)
Concerns
If you create a non-calculated field and are setting the name of the child "Details" entity to the Full Name of the contact record with the "-Details" at the end you will need to concern yourself with the possibility that the name of the Contact could change (i.e. marriage / divorce). This will cause your name on this record to be out of sync with the contact's name. There are solutions that you can install that will go through and update child records that relate to a parent (as workflow does not natually do this), please let me know if you would like me to provide this...
Secondary Recommendation if 1st approach does not work
1. Setup workflow that will set the value appropriately after you create the record. You will not see the value filled in on the form initially but as soon as you save it will show up because you could setup as a synchronous workflow.
2. You would need to setup the process to handle the change to the contact's name to update the name field on this entity. Let me know and I can find this solution for you.
Hope this makes sense and solves your question. Please mark verified if so.
Thanks,
This is what I have so far, but not working.
function appendContactDetail(){ var contactName = window.parent.frames[0].Xrm.Page.getAttribute("fullname") Xrm.Page.getAttribute("new_name").setValue( currentName + '-ContactDetail'); }
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