Skip to main content



No record found.

Microsoft Dynamics AX forum

Modifying enum field based on another field value

Posted on by 105

I am working on a project about making reservations. I have a reservation table that holds the enum field Status. And reservation lines table that holds the NoYes - Paid field.
The task is I have to iterate through all lines in res lines table and see if the NoYes Paid field is yes. If this field is yes on all lines in a given reservation, the field Status in res table has to change its status to Paid.
Any suggestions how should I implement this?

This is the code I tried, but nothing changes

public void modifiedField(FieldId _fieldId)
         axmResLines_SJ reslines;

switch (_fieldId)
    case fieldNum(axmReservation_SJ, ReservationStatus):
        while select* from reslines
           where reslines.ReservationId == this.ResId
           if (reslines.Paid == NoYes::Yes)
                this.ReservationStatus = AXMReservationStatus_SJ::Paid;



  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 225,526 Super User on at
    RE: Modifying enum field based on another field value

    Using a while select loop is unncessary and it's bad for performance. Also, your code wouldn't even work correctly - it sets Status to Paid if any of the lines is Paid, not if all are paid.

    What you really want to do is checking if there isn't any line with Paid == No:

    select firstOnly RecId from unpaidResLine
       where unpaidResLine.ReservationId == this.ResId
          && !unpaidResLine.Paid;
    if (!unpaidResLine.RecId)
        this.ReservationStatus = AXMReservationStatus_SJ::Paid;

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,835 Super User

Martin Dráb Profile Picture

Martin Dráb 225,526 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans