Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

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

Posted on by 203

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:
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,565 Super User 2024 Season 2 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 73,565 Super User 2024 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
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 9,536 Super User 2024 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
  • Nil@@m Profile Picture
    Nil@@m 203 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,
  • Verified answer
    Nil@@m Profile Picture
    Nil@@m 203 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 9,536 Super User 2024 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
  • Nil@@m Profile Picture
    Nil@@m 203 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 9,536 Super User 2024 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.");
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 9,536 Super User 2024 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

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans