Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

how to use javascript to fill parent lookup on form

Posted on by 5

hi guys. I have a requirement that is so important to me. In phonecall form I have three custom field parent account(lookup) and account(lookup) and Contact(lookup). now I want a JavaScript implementation that help me when I fill account field after that fill parent account lookup with correct data or if I fill contact lookup first of all fill account with correct data then fill parent account field with correct data. I search many ways but I couldn't find any way to find correct parent account and fill my lookups even i use business rules but it can't help me. please help me as soon as possible.

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: how to use javascript to fill parent lookup on form

    Hi Zare_modernbanking,

    Andrew has provided you with the answer. You need to use the setLookupField function from the article to meet your requirement.

    // Set the Lookup Value.
    function setLookupField(executionContext) {
        var formContext = executionContext.getFormContext();
        var lookupData = new Array();
        var lookupItem = new Object();
        lookupItem.id = "74a968c5-6505-ea11-a81e-000d3a300ec6";
        lookupItem.name = "Nancy";
        lookupItem.entityType = "contact";
        lookupData[0] = lookupItem;
        formContext.data.entity.attributes.get("parentcontactid").setValue(lookupData);
    
    }

    lookupItem.id needs to be the GUID of the lookup record, lookupItem.name need to be the name of the lookup record, and lookupItem.entityType needs to be the entity of the lookup record.

  • RE: how to use javascript to fill parent lookup on form

    Thanks andrew but it couldn't help me.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: how to use javascript to fill parent lookup on form

    Hello,

    You can you JavaScript to populate those fields according to your scenario. Here are few articles that can help you:

    mscrmtechie.blogspot.com/.../getset-lookup-field-value-using.html

    carldesouza.com/.../

    To make preparation of queries easier you can use CrmRestBuilder - github.com/.../2.6.0.0

    Feel free to ask questions/share your progress.

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans