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)

Filter OData Query on expanded Entity Entity Reference field

(0) ShareShare
ReportReport
Posted on by

Hi, i have this code snippet using the provided SDK.REST.js file for a web resource to query a collection of custom related entities and sum up their totals.

function SetTotal() {
    var yearFilteredExpenses = "$select=custom_Amount&$expand=custom_custom_month_custom_expense_Month" +
                                              "&$filter=custom_ProjectExpenseId/Id eq " + FormatGuid(projectID) +
                                              "and custom_custom_month_custom_expense_Month/custom_yearmonthId/Id eq " + FormatGuid(yearID);
    SDK.REST.retrieveMultipleRecords("custom_expense",
                                     yearFilteredExpenses,
                                     ProcessExpenses,
                                     function (err) { alert("Getting Filtered Expenses by Year:" + err) },
                                     CompleteExpenses);
}
function FormatGuid(id) {
    return "(guid'" + id.replace(/[{()}]/g, '') + "')";
}


The Alert is triggered saying :

"Getting Filtered Expenses by Year:Error: Error : 500: Internal Server Error: attributeName"

I've confirmed the names of the entities and attributes as they do give different errors, and the processing and complete functions are used by other queries that work fine. The only difference in this query is the related Entity reference field filter.

Am I missing something?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    jlattimer Profile Picture
    24,562 on at

    I think your issue might be that you can only filter on a single entity - so either the primary entity OR one of the related ones.

    I've built a tool to construct OData calls in CRM which helps define what can and cannot be done. 

    https://crmrestbuilder.codeplex.com/

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