web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Pull data from related entity onLoad javscript

(0) ShareShare
ReportReport
Posted on by

Hello all,

I am trying to create a script that will run onLoad of one of my forms. Among the many things that this script will do, it needs to check a field on one of the lockups on the form.

How do i check the field value of the related record?

Thank you in advance!!

Leibish Ringel

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    litonn Profile Picture
    913 on at

    You can get information about a lookup field the following way. Lookup field consists of 3 properties together.

    var luf = Xrm.Page.data.entity.attributes.get('FIELD SCHEMA NAME HERE').getValue()

    if(luf != null){

    id= luf[0].id;

    type= luf[0].entityType;

    name = luf[0].name;

    }

    Hope this will help!

  • l ringel Profile Picture
    on at

    Thank you for you reply.

    Does this pull up the field on the related lookup or just the lookup value?

    I have entity A and B. Entity A is a parent of B. Im writing a script that runs onload of entity B and it will check the value of a given option set on the parent entity, A.

  • Suggested answer
    ntn32 Profile Picture
    401 on at

    Hey,

    To read the details of related entity from the lookup value follow the below steps

    1. On entity B form "OnLoad" script read the lookup value.

    var entitiyALookup = Xrm.Page.data.entity.getAttributes.('LookUpSchemaName').getValue()

    if(entitiyALookup != null && entitiyALookup.length[0]){

    var entityARecordId = entitiyALookup[0].id

    var entityARecordType = entitiyALookup[0].entityType

    }

    2. Now make a web API call to get the field value (in your case the optionset field value ) from entity A record.

    Xrm.WebApi.retrieveRecord(entityARecordType, entityARecordId).then(function(result){
    console.log(result);
    //Here you can read the field data from entity A. i.e., the optionset field value
    }, function(error){ console.log(error); alert(error)});

    Note: Xrm.WebApi.retrieveRecord method is only for dynamics 365 v9.0. If you are running any old version of CRM then make use of AJAX to consume the webapi.

     

    Thanks

    Nitin

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans