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, ...
Answered

Modifying enum field based on another field value

(0) ShareShare
ReportReport
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;

}

}

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,781 Most Valuable Professional on at

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

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
Martin Dráb Profile Picture

Martin Dráb 692 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 364 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans