user2993712
user2993712

Reputation: 21

Sorting on a calculated field with X++

I am a long time developer in MS Access but Now I need to develop in Microsoft Dynamics AX 2009.

I have a report that uses a method on the body of a report that calculates an "exp book date". Now I am being asked to sort on this field. I am guessing I need to move the method to the query, in order to make the field able to be sorted. But when I copy the method to the Method level of the query, it say that the field does not exist. Which it doesn't. How do i get the feild to be visiable?

display utcDatetime Test()
{
    real            AddDays;
    utcDatetime     CDate;
    ;

    AddDays = smmQuotationPrognosisGroup::find(smmOpportunityTable_1.PrognosisId, false).PrognosisDays;

    CDate = smmOpportunityTable::find(smmOpportunityTable_1.OpportunityId, false).createdDateTime;

    return DateTimeUtil::addDays(CDate, AddDays);

}

Upvotes: 2

Views: 3326

Answers (1)

DAXaholic
DAXaholic

Reputation: 35378

Unfortunately it is not possible to sort directly by a display method. Yet there are some workarounds, e.g.:

  • Use a temporary table with a field which is filled by your display method's logic before you run the report and then use this temporary table in your query.
  • Override the report's fetch method so that you have full control over fetching the data via X++.

Depending on your report's size these actions can take some time.

Upvotes: 3

Related Questions