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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Sort, range not working - fetching data from AX table using Query AIF service

(0) ShareShare
ReportReport
Posted on by 130

Hi,

I' am successfully retrieving data from Microsft Dynamics Ax2012 via AIF document services. However, it shows me all the records with no filters applied and not sorted. I didn't get any error message.

C# Example:

public async Task GetCustTableByCurrencyCodeAsync(string currencyCode)
{
    QueryResult queryResult;
    ExecuteQueryResponse executeQueryResponse;

    try
    {
        var customerDataSource = new QueryDataSourceMetadata
        {
            Table = "CustTable",
            Name = "CustTable",
            HasRelations = false,
            Enabled = true,
            DynamicFieldList = true,
            EnabledSpecified = true,
            FetchModeSpecified = true,
            DynamicFieldListSpecified = true,
            OrderModeSpecified = true
        };

        var range = new QueryDataRangeMetadata
        {
            TableName = "CustTable",
            FieldName = "Currency",
            Value = currencyCode,
            Enabled = true
        };

        customerDataSource.Ranges = new QueryRangeMetadata[] { range };

        var sort = new QueryDataOrderByMetadata
        {
            DataSource = "CustTable",
            FieldName = "AccountNum",
            SortOrder = SortOrder.Descending
        };

        var query = new QueryMetadata
        {
            QueryType = QueryType.Join,
            DataSources = new[] { customerDataSource },
            OrderByFields = new QueryOrderByMetadata[] { sort }
        };

        var paging = new PositionBasedPaging
        {
            StartingPosition = 1,
            NumberOfRecordsToFetch = 10,
            NumberOfRecordsToFetchSpecified = true,
            StartingPositionSpecified = true
        };

        ExecuteQueryRequest req = new ExecuteQueryRequest(query, paging);

        using (var client = ClientFactory.CreateClient())
        {
            executeQueryResponse = await client.ExecuteQueryAsync(req);
        }

        queryResult = createQueryResponse(ToDataSet(executeQueryResponse.ExecuteQueryResult));

    }
    catch (Exception ex)
    {
        throw new FaultException(ex.Message);
    }

    return queryResult;
}

Why is sort and filter not working?

Thank you in advance,
Janos

I have the same question (0)
  • Martin Dráb Profile Picture
    239,178 Most Valuable Professional on at

    You seem to be using the Query service, not an AIF document service.

    Unfortunately I don't see anything wrong in your code, therefore I don't have a solution for you.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 681

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 446 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 202 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans