Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
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 230,214 Most Valuable Professional 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;
    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans