Skip to main content

Notifications

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

If else in option field in bussiness central

Posted on by 208

I want that if user select option 1 do some action and user select option 2 other action to happen how can i achieve this .I tried this code but I am confused.

field(MyOptionField; Option) { Caption = 'My Option Field'; OptionValues = OptionValues::Option1..OptionValues::Option3; trigger OnValidate() var MyOption: Option; begin MyOption := this.Value; case MyOption of OptionValues::Option1: // Do something if Option 1 is selected // ... OptionValues::Option2: // Do something if Option 2 is selected // ... OptionValues::Option3: // Do something if Option 3 is selected // ... end; end; }

This is not working.

  • Pragya752 Profile Picture
    Pragya752 208 on at
    RE: If else in option field in bussiness central

    yes u r right.Here,I am not understanding syntax to do so.I did this on page level but it is didnt work out

    field("Level-01_Descrption";Rec."Level-01_Descrption")

           {

               trigger OnValidate()

               var

                   OptionsVar: Enum CashflowLevel1Description;

                   Level : Enum CashflowLevel2Description;

               begin

                   case OptionsVar OF

                       OptionsVar::"Cash Inflow":

                       begin

                       Rec."Level-02_Descrption":=  ;

                       end;

                       OptionsVar::"Cash Outflow":

                       begin

                       Rec."Level-02_Descrption":= ;

                       end;

                   end;

               end;

           }

           field("Level-02_Code"; Rec."Level-02_Code")

           {

           }

           field("Level-02_Descrption";Rec."Level-02_Descrption")

           {

           }

  • Suggested answer
    Govinda Kumar Profile Picture
    Govinda Kumar 2,203 Super User 2024 Season 1 on at
    RE: If else in option field in bussiness central

    Hi,

    If I understand correctly, you want to set different enums in other fields based on the option selected in your first field. For example, if 'cashInflow' is selected in your first enum field, then you want to set a specific enum with three options in your second field. If 'cashoutflow' is selected, then another set of three option fields should be set in the second field. If this is the case, then your code is not correct and I also recommend you to do it on the page level and using a variable as the field on the page..

    Please let me know if you need any help..

    Regards

  • Pragya752 Profile Picture
    Pragya752 208 on at
    RE: If else in option field in bussiness central

    I want that If i select cashInflow ,3 Options in form of dropdown should come from a whole set of Enum should appear in another field and if i select outflow another 3 should Appear from same set.how can i achieve this.

    field(2; "Level-01_Descrption"; Enum CashflowLevel1Description)

           {

               Editable = false;

               trigger OnValidate()

               var

                   OptionsVar: Enum CashflowLevel1Description;

               begin

                   OptionsVar := "Level-01_Descrption";

                   case OptionsVar OF

                       OptionsVar::"Cash Inflow":

                       begin

                       "Level-02_Descrption":= "Level-02_Descrption":: ???????????????

                       end;

                       OptionsVar::"Cash Outflow":

                       begin

                       "Level-02_Descrption":= "Level-02_Descrption":: ????????????

                       end;

                   end;

               end;

           }

           field(3; "Level-02_Code"; Enum CashFlowLevel2Code)

           {

           }

           field(4; "Level-02_Descrption"; Enum CashflowLevel2Description)

           {

           }

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: If else in option field in bussiness central

    You can try as per below

    var

           OptionVar: Option "A","B","C";

       begin

           case OptionVar OF

               OptionVar::A:

                   begin

                   end;

               OptionVar::B:

                   begin

                   end;

           end;

       end;

  • Verified answer
    Deekshitha Reddy Profile Picture
    Deekshitha Reddy 219 on at
    RE: If else in option field in bussiness central

    You can use the below code(FORMAT) ,

    Here Select Type is the field name of the type Option and Withdraw, Renew are values.

    Call this procedure in trigger OnValidate of Option & try giving a message in place of code.

    procedure SelectOption()

       begin

    case "Select Type" OF

               rec."Select Type"::Withdraw:

                   begin

                        // code

                    end;

    case "Select Type" of

               rec."Select Type"::Renew:

                   begin

                        //code

                    end;

         end;

    Please let me know.

    Hope this Helps.

  • Pragya752 Profile Picture
    Pragya752 208 on at
    RE: If else in option field in bussiness central

    I am not getting how to get the value of the option that user selects.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: If else in option field in bussiness central

    You can try with Case..End statement with below link

    learn.microsoft.com/.../devenv-al-control-statements

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!

Community AMA December 12th

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

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans