web
You’re offline. This is a read only version of the page.
close
Skip to main content
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 273

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,364 Super User 2025 Season 2 on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    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
    273 on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    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,364 Super User 2025 Season 2 on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    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,364 Super User 2025 Season 2 on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    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
    273 on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    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,364 Super User 2025 Season 2 on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    Hi,
     
    Please share with me the Enum WeekDays
     
    BR
  • Verified answer
    Test user Profile Picture
    273 on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    Hi Mohamed,
     
    Yes this case statment code is working now.
    Thank you for your guidance.
  • Test user Profile Picture
    273 on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    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,364 Super User 2025 Season 2 on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    Hi,
     
    please ensure this order :
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    YUN ZHU Profile Picture
    94,353 Super User 2025 Season 2 on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,901

#2
YUN ZHU Profile Picture

YUN ZHU 2,079 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 2,041

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans