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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans