Skip to main content
Business Central forum
Suggested answer

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

editSubscribe (3) ShareShare
ReportReport
Posted on by 65

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? 

Categories:
Attachments
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 60,219 Super User on at
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
    Hi, I just thought, you can also do it using the Format method.
     
    Hope this helps as well.
    Thanks.
    ZHU
  • Suggested answer
    How to write switch case statment condition in AL lagunage (For weekdays like Monday->sunday)
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 60,219 Super User 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
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 3,684 User Group Leader 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
  • Community member Profile Picture
    Community member 65 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,
  • Community member Profile Picture
    Community member 65 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.
  • Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 3,684 User Group Leader 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
  • Community member Profile Picture
    Community member 65 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.
     
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 3,684 User Group Leader 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.");
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 3,684 User Group Leader 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

Helpful resources

Quick Links

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,176 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,727 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans