Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Help getting fields from a related entity through a lookup in javascript

(0) ShareShare
ReportReport
Posted on by 387

Hi,

Looking for how to do this? I have a lookup field on one form... I want to get other data from the selected record in the lookup field to populate another field on the form.

I've found a million articles with the same stuff.. that shows how to get id, name, and type... but I want to get a different fields from those from the original record, in this case users entity.

This works to get id from new_user lookup field on form.

function GetUserDetails(executionContext) {
var formContext = executionContext.getFormContext();
var entityId = formContext.getAttribute("new_user").getValue()[0].id.slice(1,-1);

alert(entityId);

}

But can't use it to get fullname for example?

Doing this doesn't work:

formContext.getAttribute("new_user").getValue()[0].fullname;

Anyone help with missing piece?

Thanks,

Terry

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Help getting fields from a related entity through a lookup in javascript

    Terry,

    I'm glad that you resolved your issue. And just for your understanding - I'm not for the "giving the fish" I'm for the "teaching to fish" approach if you understand that.

  • Mattw112b Profile Picture
    387 on at
    RE: Help getting fields from a related entity through a lookup in javascript

    marked this as the answer, but would've been nicer if there was some direct examples or something... but after trial and error I have it working.  For others looking for this here's what I did:

    function GetUserDetails(executionContext) {
    var formContext = executionContext.getFormContext();
    var entityId = formContext.getAttribute("new_user").getValue()[0].id.slice(1, -1);

    if (entityId !== null) {

    Xrm.WebApi.retrieveRecord("systemuser", entityId, "?$select=fullname").then(

    function success(result) {
    if (result !== null) {

    //set text field
    if (result.fullname !== null)
    formContext.getAttribute("new_name").setValue(result.fullname);
    }
    },
    function(error) {
    alert(error.message);
    }
    );
    }
    }

    Thanks,

    Terry

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Help getting fields from a related entity through a lookup in javascript

    Hello Terry,

    You will need to use Xrm.WebApi for this purpose. Check this post - carldesouza.com/.../

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 149 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 57

#3
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 53 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans