Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

If we have account ID then how to get related contacts

(0) ShareShare
ReportReport
Posted on by

Hi,

When i open any account entry, then I get accountID using this script:

var accountId=Xrm.Page.data.entity.getId();

and i want related contacts bind in any textbox on the behalf of account.

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: If we have account ID then how to get related contacts

    Hi,

    This might help you

    docs.microsoft.com/.../retrieve-entity-using-web-api

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: If we have account ID then how to get related contacts

    Hi ,

    You can implement  below code

    var accountId = Xrm.Page.data.entity.getId();

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/contacts?$select=firstname,lastname,fullname&$filter=_accountid_value eq " + accountId + "", false);

    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.maxpagesize=10");

    req.onreadystatechange = function () {

    if (this.readyState === 4) {

    req.onreadystatechange = null;

    if (this.status === 200)

    {

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

    for (var i = 0; i < results.value.length; i++)

    {

    var firstnaem = results.value[i]["firstname"];

    }

    }

    else

    {

    alert(this.statusText);

    }

    }

    };

    req.send();

    }

  • Suggested answer
    Preeti Sharma Profile Picture
    2,678 on at
    RE: If we have account ID then how to get related contacts

    Hi,

    You can get it using quick view form as well.Please check below link:

    community.dynamics.com/.../252551

    Hope this helps:)

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: If we have account ID then how to get related contacts

    Hello,

    Here is the code -

           var accountId = Xrm.Page.data.entity.getId();

           var req = new XMLHttpRequest();

           req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/contacts?$select=firstname,lastname&$filter=_accountid_value eq " + accountId + "", false);

           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.onreadystatechange = function () {

               if (this.readyState === 4) {

                   req.onreadystatechange = null;

                   if (this.status === 200)

                   {

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

                       for (var i = 0; i < results.value.length; i++)

                       {

                           var firstname = results.value[i]["firstname"];

                       }

                   }

                   else

                   {

                       //Error

                   }

               }

           };

           req.send();

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at
    RE: If we have account ID then how to get related contacts

    Hi,

    please take a look - https://community.dynamics.com/crm/f/117/t/268428

    I have shared the code for the similar requirement. Hope it helps

    Mark this an answer, If it helps.

     

    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.in

     

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: If we have account ID then how to get related contacts

    Hi,

    You would need to write custom javascript code to retrieve the related contacs for that account using Web API.

    refer this-

    community.dynamics.com/.../ms-crm-2016-web-api-operations-retrieve-single-or-multiple-records

    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

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans