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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get attribute/field value of parent entity

(0) ShareShare
ReportReport
Posted on by 215

Good morning people.

I was wondering how to get a attribute/field value of a parent entity?

I am getting the GUID of the parent through a lookup field with the following code:

var potentialSupplier = Xrm.Page.getAttribute("new_potentialsupplier").getValue();

and this is ok it gets me the GUID.

Now the problem im facing is how to get all the attributes of this record and access another lookup field which is an attribute of the first lookup and get it's GUID so i can use it in creating a Custom View?

Any advice is welcomed.

Cheers Filip.

*This post is locked for comments

I have the same question (0)
  • Filip Vanchevski Profile Picture
    215 on at
    RE: Get attribute/field value of parent entity

    Works like a charm, thank you all :)

  • Filip Vanchevski Profile Picture
    215 on at
    RE: Get attribute/field value of parent entity

    I gave you all verified status because you pointed me in the right direction but instead of writing my own web api i used:

    var potentialSupplier = Xrm.Page.getAttribute("new_potentialsupplier").getValue();
        var potentialSupplierID
        if (potentialSupplier != null) {
            potentialSupplierID = potentialSupplier[0].id;
        }
    
        var fetchProducer = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                             "<entity name='account'>" +
                                "<attribute name='name'/>" +
                                "<attribute name='primarycontactid'/>" +
                                "<attribute name='telephone1'/>" +
                                "<attribute name='accountid'/>" +
                              "<order attribute='name' descending='false'/>" +
                                "<link-entity name='lead' from='new_producer' to='accountid' alias='ab'>" +
                                    "<filter type='and'>" +
                                        "<condition attribute='leadid' operator='eq' value='" + potentialSupplierID + "'/>" +
                                    "</filter>" +
                                "</link-entity>" +
                             "</entity>" +
                            "</fetch>";
        var producer = XrmServiceToolkit.Soap.Fetch(fetchProducer);


    and Voila the id of the account i was looking for.

    Thank you all, hopefully i can now use the id of the producer in my next fetch and build the Custom View.... i will update you if it works or if i get stuck somewhere.

  • Filip Vanchevski Profile Picture
    215 on at
    RE: Get attribute/field value of parent entity

    I will test both of the answers and let you know where i get stuck, will verify one of the answers as soon as i have results.

    Cheers.

    Filip.

  • Verified answer
    Iswarya Profile Picture
    1,347 on at
    RE: Get attribute/field value of parent entity

    Hi,

    use this script to get parent entity attributes, after getting lookupfield guid, pass this guid to parent entity primary key to retrieve parent record as follows

    function RetrieveparentRecord() {
        debugger;

        var potentialSupplier = Xrm.Page.getAttribute("new_potentialsupplier").getValue();
    if(potentialSupplier!=null)
    {
    var potentialSupplierID=potentialSupplier[0].id;

        var context = Xrm.Page.context;

        var serverUrl = context.getClientUrl();

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

        var retrieveResult = new XMLHttpRequest();

    //new_PotentialsupplierName,new_PotentialSupplierLookup,.....(here include what are the fields required from parent entity)
        retrieveResult.open("GET", ODataPath + "/new_potentialSupplierSet?$select=new_PotentialsupplierName,new_PotentialSupplierLookup&$filter=new_PotentialSupplierId/Id eq guid'" + potentialSupplierID + "'", 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];
                if (typeof Result !== "undefined") {

                    var lookupValue = new Array();
                    lookupValue[0] = new Object();
                    lookupValue[0].id = Result.new_PotentialSupplierLookup.Id;
                    lookupValue[0].name = Result.new_PotentialSupplierLookup.Name;
                    lookupValue[0].entityType = Result.new_PotentialSupplierLookup.LogicalName;            

                  
                }

            }

        }
    }
    }

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: Get attribute/field value of parent entity

    Hi,

    You can write a WEPAPI request to get other fields based on the GUID, so you can write retrieve call, check sample code here http://himbap.com/blog/?p=1997 or you can use restbuilder to build your web api request:

    github.com/.../CRMRESTBuilder

    Thanks

  • Verified answer
    Guido Preite Profile Picture
    54,084 Moderator on at
    RE: Get attribute/field value of parent entity

    you need to do a call to fetch the record, as you are using crm 2016 you can use webapi, in order to build the query and the js code you can use this tool from Jason Lattimer

    https://github.com/jlattimer/CRMRESTBuilder/releases

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans