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 :
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
    237,976 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

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans