Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    ntn32 Profile Picture
    401 on at
    RE: Pull data from related entity onLoad javscript

    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

  • l ringel Profile Picture
    on at
    RE: Pull data from related entity onLoad javscript

    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
    litonn Profile Picture
    913 on at
    RE: Pull data from related entity onLoad javscript

    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!

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 CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans