Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Pull data from related entity onLoad javscript

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
    ntn32 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
    l ringel 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
    litonn 911 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans