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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Customer Service forum

Is there a way to get a custom attribute of lookup.

(0) ShareShare
ReportReport
Posted on by 244

Desc: I have a case form and have custom look up on it which has an email attribute.

I want to to check whether the particular custom lookup record has value for email field in js that is on case form?

var a=formContext.getAttribute("new_customlookup");

if(a != null)

{

how to get email address of record a;

}

Categories:
I have the same question (0)
  • Suggested answer
    Ben Thompson Profile Picture
    6,350 on at

    To get the email address you need to query the record and request the email address from that record.

    James Lattimer's CRMRestBuilder will generate the Javascript you require to query the record. You can download it  from https://github.com/jlattimer/CRMRESTBuilder/releases/tag/2.6.0.0 

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    Hi..

    In addition to Ben, here is sample code to retrieve email address from your custom lookup field

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts(1B8C0622-6E90-E811-80D8-005056B1622D)?$select=emailaddress1", true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.setRequestHeader("Accept", "application/json");

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

    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 200) {

               var result = JSON.parse(this.response);

               var emailaddress1 = result["emailaddress1"];

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

    You need changes in above code.. please check highlighted details

    Instead of contacts use your custom lookup entity name, Guid you need to pass custom lookup id, emailaddress1 field should be email attribute from your custom entity. 

    Hope this will help.. 

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    As mentioned above, you need to retrieve the lookup details using WEB API. You can refer below blog on the same-

    community.dynamics.com/.../get-lookup-value-from-other-entity-and-set-it-on-the-form-using-web-api-in-microsoft-dynamics-crm

    Hope this helps.

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Customer Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans