Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to Pull all the contacts for a particular account in CRM Webapi??

Posted on by Microsoft Employee

I need all the contacts belongs to a particular account .Is there any way to pull contacts  in CRM webapi ?

*This post is locked for comments

  • Suggested answer
    prt33k Profile Picture
    prt33k 6,907 on at
    RE: How to Pull all the contacts for a particular account in CRM Webapi??
    function retireveContacts() {
        var accountId = Xrm.Page.getAttribute('<acconut lookup schema name>').getValue();
        var req = new XMLHttpRequest();
        req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/contacts?$select=firstname,lastname,_ownerid_value&$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.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
        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 firstname = results.value[i]["firstname"];
                        var lastname = results.value[i]["lastname"];
                        var _ownerid_value = results.value[i]["_ownerid_value"];
                        var _ownerid_value_formatted = results.value[i]["_ownerid_value@OData.Community.Display.V1.FormattedValue"];
                    }
                }
                else {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }


    Firstly, what is the lookup name for account. I dont think it is parentcustomerid. Whatever it is , replace in belo code and then try

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: How to Pull all the contacts for a particular account in CRM Webapi??

    Hi,

     isn't it the same question you were asking yesterday? What did not work?

    community.dynamics.com/.../243728

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How to Pull all the contacts for a particular account in CRM Webapi??

    Hi Joy,

    You could use the following URL in web API to get all the contacts belonging to a particular account.

    Hope this helps.

  • Suggested answer
    Samrando Profile Picture
    Samrando 270 on at
    RE: How to Pull all the contacts for a particular account in CRM Webapi??

    community.dynamics.com/.../195801

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans