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)

read related entity id from a related entity using java script SDK REST javascript

(0) ShareShare
ReportReport
Posted on by

Hi Dynamics community , 

one of my colleague create an new custom entity call related service rentals in CRM 2016 which has look up field to Quote . Also this new custom entity has a another look up field call service rental. now what he wants to do is add list of service rentals to the Quote .   so when we go add new related service rental it automatically populate quote we need to filter the look up for service rentals which belong to same customer as Quote.

does this make sense ?

I am trying to read Quote custome id from SDK REST and then use that customerid to filter the look up for related service rental so it's easy for user to find the record.

I have found this post about filtering look up http://www.inogic.com/blog/2015/08/apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script/

but I am failing to get customer id from linked quote. 

this what i tried and I get Unable to get property 'id' of undefined or null reference error

  var quotelookup = Xrm.Page.getAttribute("new_relatedquoteid").getValue();
        if (quotelookup != null)
        {
            var quoteid = quotelookup[0].id;

            SDK.REST.retrieveRecord(
            quoteid,
            "Quote",
            "CustomerId", null,
            function (quote) {
                var customerlookup = quote.CustomerId;
                if (customerlookup != null && customerlookup != undefined) {                   
                    var customerid = customerlookup[0].id;
                    alert(customerlookup + customerid);
                }
                else {
                    alert("undefined customer");
                }

            },
            errorHandler
            );
        }


any idea how to approach this please ?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: read related entity id from a related entity using java script SDK REST javascript

    Hello,

    Replace line

    var customerid = customerlookup[0].id;

    with line

    var customerid = customerlookup.Id;

  • Community Member Profile Picture
    on at
    RE: read related entity id from a related entity using java script SDK REST javascript

    Hi thanks it worked :)

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans