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

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello Terry,

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

  • Mattw112b Profile Picture
    387 on at

    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

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
iampranjal Profile Picture

iampranjal 51

#2
Martin Dráb Profile Picture

Martin Dráb 39 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 26 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans