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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

assign enum value to another enum value

(0) ShareShare
ReportReport
Posted on by 115

Hi All,

I have requirement to assign a string value to another enum value. Please find the below code

LeaveSetup.LeaveCategory  =  any2Enum(LeaveTypes.MPLeaveGroup);

LeaveSetup.LeaveCategory - enum value

LeaveTypes.MPLeaveGroup - string value

 

i tried to use any2enum and str2enum but i didn't get the expected answers.

Can anyone help me to achieve this?

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Hameed,

    What is your exact requirement here? You have to save Enum values in an enum field.

    Are you looking to convert the string to an enum value?

  • AnithaEswaran Profile Picture
    2,032 on at

    Hi Baduru,

    Can you elaborate your requirement ?

    You can assign only enum value to enum.  To assign to a string variable, try to bring a new field.

    We can help you, if you throw more light on your needs.

  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    Assuming that your users can create any "MPLeaveGroup" values (string), there's no way how you could always convert them to enum values.

    If you have a table for "MPLeaveGroup", just add a new enum field there, so that users must specify LeaveCategory enum value when they create a new Leave group.

    My advice is based on guessing your actual requirement because I don't know enough details. Feel free to share more details if you want better advice. Thanks!

  • baduru hameed Profile Picture
    115 on at

    Thank you all for your quick response,

    I got the solution, Now i need how can i assign enum field value to another enum field

    LeaveSetup.LeaveCalcMethod = LeaveTypes.MPWorkCalendar;

    both fields are enum fields. this code throw an error.

    Please suggest me how can i achieve this.

  • nmaenpaa Profile Picture
    101,166 Moderator on at

    If they are different enums, you can't (and definetely shouldn't) set value from another to the other.

    What would be the point in that?

    If your two enums are somehow related, then you could develop a conversion table where you map the values to each other.

    Please share your business requirement with us. Also please share all values of your both enums with us, perhaps it helps us understand what you are trying to achieve.

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Hameed, are the enum types of fields "LeaveCalcMethod" and "MPWorkCalendar" the same? In case they are not, you will get an error.

    Please mention your business requirement here so that we can help you better.

  • baduru hameed Profile Picture
    115 on at

    Thank you all for your response.

    I have 2 forms Named SDSLeaveSetup and MPLeaveTypes

    SDSLeaveSetup:

    SDSLeaveReq.png

    MPLeaveTypes

    MPLeavetypes.png

    in MPLeaveTypes we have field called calculation method and same field in SDSleaverequest form but in different enum. In my requirement is while select the drop down in MPLeaveTypes the selected records should update in SDSleaverequest form fields.

    I have written my logic through class and a button in SDSleaverequest form  i can achieve in all fields but now i need to update this field value.

    please suggest me.

  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    Why are you using different enums in these tables? If both enums have same options and if you must be able to pass values from one field to another, then clearly you need to use same enum in both fields!

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    I think you can use the same enum in both fields, since they are essentially the same values.

    In case you have a requirement wherein you might want to add more values to any of the enums, you may implement a switch statement like this-

    LeaveCalcMethod leaveCalcMethod;
    
    switch (LeaveTypes.MPWorkCalendar)
    {
    	case MPWOrkCalendar::WorkingDays:		
    		leaveCalcMethod = LeaveCalcMethod::WorkingDays;
    		break;
    
    	case MPWOrkCalendar::CalendarDays:		
    		leaveCalcMethod = LeaveCalcMethod::CalendarDays;
    		break;
    }
    
    LeaveSetup.LeaveCalcMethod = leaveCalcMethod;

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 659

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 465 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 304 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans