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

  • Martin Dráb Profile Picture
    233,029 Most Valuable Professional on at
    RE: Sort, range not working - fetching data from AX table using Query AIF service

    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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,349 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,029 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans