Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

CRM 2016 Javascript - Getting values from fields on parent account to populate matching fields on opportunity

Posted on by Microsoft Employee

We have a series of fields on our account and opportunity fields that are lookups to the account entity. By default when you create these fields the system creates an automatic mapping from the field to the Accountid. This pulls the account name into this field on the opportunity when the record is created from the account. We would like to overwrite this value with the companion field that is on the account. IE if we have a associatedaccount field on the account that is a lookup to an account record and a associatedaccount field on the opportunity entity that is a lookup to an account record. We want the value that is in the account associatedaccount field to populate on the opportunity customer field. However what happens is the parent account name populates on the opportunity associatedaccount field rather than the account that is listed in the account associatedaccount field.

I am trying to find a way to write javascript on create of the opportunity form to pull the associatedaccount from the parent account via the relationship of customerid and populate on the opportunity form in the associatedaccount field. Any assistance would be greatly appreciated.

Jenn

*This post is locked for comments

  • Verified answer
    Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: CRM 2016 Javascript - Getting values from fields on parent account to populate matching fields on opportunity

    Hi Jenn,

    Here's an example of the getParent method in use:

    www.resultondemand.nl/.../6881e99b-45e4-4552-8355-2eef296f2cd8.htm

    I'm haven't used it but I'm not sure that'll get you what you want. The documentation says it returns the Xrm.Page.data.entity object, so that would be your opportunity record and not the account. Again, I have used it so it may actually work differently.

    Thanks!

     Aiden

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM 2016 Javascript - Getting values from fields on parent account to populate matching fields on opportunity

    Thank you Aiden. This is somewhat helpful however I am wondering if anywhere there is an example of using the getParent method.

    Jenn

  • Suggested answer
    Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: CRM 2016 Javascript - Getting values from fields on parent account to populate matching fields on opportunity

    Hi Jen,

    It sounds like you can do that with a business rule instead of JS - technet.microsoft.com/.../dn531086.aspx

    If you don't have any luck with the business rules, you can do it with javascript on load of the opportunity record.

    Here's how you'd get the attribute for the account lookup you want to use: msdn.microsoft.com/.../gg334409.aspx

    Here's documentation on how to do a retrieve for an account, given an account ID: msdn.microsoft.com/.../gg334427.aspx

    so you want to check and see if the account lookup has a value, retrieve the account record based on the lookup ID, then set the value on your opportunity form.

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

     Aiden

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans