Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

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;
         super(_fieldId);

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;
          }
      }
     break;

}

}

  • 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 . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 225,526 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans