Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Populate Quick Create Form with Data from Parent Form using JavaScript

Posted on by Microsoft Employee

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

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Populate Quick Create Form with Data from Parent Form using JavaScript

    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);

  • Verified answer
    Drew Poggemann Profile Picture
    Drew Poggemann 9,079 on at
    RE: Populate Quick Create Form with Data from Parent Form using JavaScript

    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,

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Populate Quick Create Form with Data from Parent Form using JavaScript
    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'); }



Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans