web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)

(3) ShareShare
ReportReport
Posted on by 321

Hi Guys,

I have two fields on my call distribution page.1 Delivery date 2.Delivery Date. 

& this Delivery day fields has Enum values.. Mon....Sun like this. as you can see on below screenshot.

I want ,if I select whatever date ,then date relted day will be populated on Delivery day field. 

For example : 28/03/2024 -> Thursday, 27/03/2024->Wednesday. 

But all this done through a Switch case statement in AL language.

I am writing this logic as seen on below scrrenshot.this logic is also correct.

But As per our requirement we write the code as per switch case statment.

How to do this? 

I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,779 Super User 2026 Season 1 on at
    Hi,
    Try this:
                trigger OnValidate()
                var
                    dt: Record Date;
                begin
                    if dt.Get(dt."Period Type"::Date, "Delivery Date") then
                        "Dilvery Day" := dt."Period Name";
                    
                end;
    Best regards,
    Mohamed Amine MAHMOUDI
     
  • Test user Profile Picture
    321 on at
    Hi Mohamed,
    My devliery day is enum field,& System period name is text field.
    That's why i told alredy ,i want to do this on switch case statment logic
  • Verified answer
    Mohamed Amine Mahmoudi Profile Picture
    26,779 Super User 2026 Season 1 on at
    Hi,
     
    try this :
    trigger OnValidate()
    var
        dt: Record Date;
    begin
        if dt.Get(dt."Period Type"::Date, "Delivery Date") then
        begin
            case dt."Period No." of
                1:
                    "Dilvery Day" := Rec."Dilvery Day"::Monday;
                2:
                    "Dilvery Day" := Rec."Dilvery Day"::Tuesday;
                3:
                    "Dilvery Day" := Rec."Dilvery Day"::Wednesday;
                4:
                    "Dilvery Day" := Rec."Dilvery Day"::Thursday;
                5:
                    "Dilvery Day" := Rec."Dilvery Day"::Friday;
                6:
                    "Dilvery Day" := Rec."Dilvery Day"::Saturday;
                7:
                    "Dilvery Day" := Rec."Dilvery Day"::Sunday;
            end;
        end;
    end;
    Best regards,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,779 Super User 2026 Season 1 on at
    Hi,
    Also you can assign the value without case statement if the values of enum ordred from 1 to 7 (monday to sunday).
     
    "Dilvery Day" := Enum::"Dilvery Day".FromInteger(dt."Period No.");
  • Test user Profile Picture
    321 on at
    Hi Mohamed,
    As you suugessted the answer,i am writing this,but it couldn;t get right delivery day.
    like as i select the todays date,but it get wrong delivery day. as you can see on below scrrenshot.
     
    27/03/2024 ....Today is Thursday, but on delivery day field shows wednesday.
     
  • Mohamed Amine Mahmoudi Profile Picture
    26,779 Super User 2026 Season 1 on at
    Hi,
     
    Please share with me the Enum WeekDays
     
    BR
  • Verified answer
    Test user Profile Picture
    321 on at
    Hi Mohamed,
     
    Yes this case statment code is working now.
    Thank you for your guidance.
  • Test user Profile Picture
    321 on at
    Hi Mohamed,
    my Enum Weekdays are Monday to sunday. Total 8 values .Monday to sunady is 7 values & 1 blank value,
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,779 Super User 2026 Season 1 on at
    Hi,
     
    please ensure this order :
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    YUN ZHU Profile Picture
    98,223 Super User 2026 Season 1 on at
    Hi, I think it doesn't need to be so complicated. You can get "week" just using the following standard method.
    System.Date2DWY(Date, Integer) Method
     
    Hope this helps.
    Thanks.
    ZHU

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,960 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,084 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 1,047 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans