Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Can we design odata query by applying filter on secondary entity?

Posted on by Microsoft Employee

For example account has 4 contacts, out of which I need to retrieve contact id of a contact which has phone number

*This post is locked for comments

  • Suggested answer
    imayur Profile Picture
    imayur 630 on at
    RE: Can we design odata query by applying filter on secondary entity?

    Use CRM Rest Builder for creating Rest data queries.

    Refer below code

    var contacts = $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts?$select=contactid&$filter=_accountid_value eq 6d5f2230-8091-4fbf-9cbf-ae9f712c8a79 and  mobilephone ne null",
        beforeSend: function(XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
            XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
            XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
        },
        async: true,
        success: function(data, textStatus, xhr) {
            var results = data;
            for (var i = 0; i < results.value.length; i++) {
                var contactid = results.value[i]["contactid"];
            }
        },
        error: function(xhr, textStatus, errorThrown) {
            Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
        }
    });

    Or you can create fech xml to build above query and concat you paramaters for query in fetch xml

    and put in below field (Check screnshot) 

    2450.1111.JPG

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans