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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

If else in option field in bussiness central

(0) ShareShare
ReportReport
Posted on by 234

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.

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

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

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

  • Pragya752 Profile Picture
    234 on at

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

  • Verified answer
    Deekshitha Reddy Profile Picture
    219 on at

    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.

  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    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;

  • Pragya752 Profile Picture
    234 on at

    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
    Govinda Kumar Profile Picture
    2,304 Moderator on at

    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
    234 on at

    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")

           {

           }

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans