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

How to catch parent record guid from grand child using javascript?

(0) ShareShare
ReportReport
Posted on by

hi,

i have a requirement.i have 3entities A,B and C. A to B there is 1 to n relationship and B to C there is 1 to n relationship..when i am working on C entity i want to catch the guid of the parent record with reference of b entity using javascript

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Iswarya Profile Picture
    1,347 on at

    Hi,

    C entity will have B entity lookupfield (like field name is B)  from which u can get id of B entity. after getting B id , pass this id to B entity primary key and get the corresponding record ,from which we can get guid of A lookupfield.  call this script in onsave of C entity

    function GetRecid()

    {

    var bValue=Xrm.Page.getAttribute("new_b").getValue();

    if(bValue!=null)

    {

    var bId=bValue[0].id;

      var context = Xrm.Page.context;

        var serverUrl = context.getClientUrl();

        var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

        var retrieveResult = new XMLHttpRequest();

        retrieveResult.open("GET", ODataPath + "/new_BSet?$select=new_A&$filter=new_Bid/Id eq guid' " + bId+ "'", false);
        retrieveResult.setRequestHeader("Accept", "application/json");

        retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8?");

        retrieveResult.send();

        if (retrieveResult.readyState == 4 /* complete */) {
            if (retrieveResult.status == 200) {
                var retrieved = this.parent.JSON.parse(retrieveResult.responseText).d;


                var Result = retrieved.results[0];
                var TotalVal = 0;
                if (typeof Result !== "undefined") {
                 

             //to get value of A entity Lookup field id
                        var lookupValue = new Array();
                        lookupValue[0] = new Object();
                        lookupValue[0].id = Result.new_A.Id;
                        lookupValue[0].name = Result.new_A.Name;
                        lookupValue[0].entityType = Result.new_A.LogicalName;                     
    }

    }

    }

    }

    }

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at

    Hi Tejagupta,

    You are working on C entity and there is 1:N between B and C.

    So there must be lookup field of B in C entity.

    Easily you can get the lookup field id that is guid.

    var name = Xrm.Page.getAttribute('<FIELD_NAME>').getValue()[0].name;

    var id =  Xrm.Page.getAttribute('<FIELD_NAME>').getValue()[0].id;

    Hemant

  • Community Member Profile Picture
    on at

    Thanks for your response..here is my requirement

    function GetData()

    {

    var stateid=Xrm.Page.getAttribute("tj_state").getValue()[0].id;

    var statename=Xrm.Page.getAttribute("tj_state").getValue()[0].name;

    //alert(stateid);

    //alert(statename);

    var statecolumns=["tj_country","tj_religion"];

    var obj=XrmserviceToolkit.Soap.Retrieve("tj_state",stateid,statecolumns);

    //here 'tj_religion' is single line of text,am able to catch the value inside that but,'tj_country'

    is the lookup how can i catch the lookup field data and id of that?

    var religionname=obj.attributes['tj_religion'].value;

    var countryid=obj.attributes['tj_country']. ??

    }

  • Verified answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at

    var countryid=obj.attributes['tj_country'].Id

    This should work.

  • Community Member Profile Picture
    on at

    i tried that but not working bro

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at

    I would suggest debug.

  • Verified answer
    Iswarya Profile Picture
    1,347 on at

    Hi ,

    when you debug in developer tool , obj.attributes['tj_country'] add this into watch expression and you will able to get idea .

  • Community Member Profile Picture
    on at

    Finally got it but 'i' should be in lowercase

    var countryid=obj.attributes['tj_country'].id;

    Thanks for your 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

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

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans