web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

I have the same question (0)
  • 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 201

#2
DAnny3211 Profile Picture

DAnny3211 134

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 129 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans