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

Announcements

News and Announcements icon
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

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at

    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
    gdas Profile Picture
    50,091 Moderator on at

    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
    Preeti Sharma Profile Picture
    2,678 on at

    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

    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
    Community Member Profile Picture
    on at

    Hi,

    This might help you

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

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans