Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to see if str2Enum returns nothing

(0) ShareShare
ReportReport
Posted on by

Hi

If I call str2enum, e.g like this,

NoYes ny;
ny = str2enum(ny, 'badvalue');

what value will ny get? I can see in the debugger that it does not have Yes, not No. It is just blank. But I have not found a working way to identify this in a if clause.

(!ny) does not work

(ny==null) does not work

Any ideas?

 

 

*This post is locked for comments

  • skaue Profile Picture
    Moderator on at
    Re: How to see if str2Enum returns nothing

    So basically this works:

    static void Adtest_enum(Args _args)
    {
        NoYesCombo      n;
        ;
        if (!enum2str(str2Enum(n, 'bad')))
        {
            info('bad enum');
        }
    }
    
  • Suggested answer
    Denis Patrakov Profile Picture
    on at
    Re: How to see if str2Enum returns nothing

    Usually all enum values have nonblank labels (if not then it's not good at all as you cannot use a blank enum label in a query range) so you can call enum2str(ny) and check if it returns a blank string. If it does then the enum variable definitely holds an invalid value. Internally in case of an incorrect conversion AX assigns a value of 255 to an enum variable (in MorphX a maximum enum value that you can use is 250) but this is kind of... undocumented so enum2str() is a preferable way to check if a preceding str2enum() call returned a valid enum value.

  • somvir gahlawet Profile Picture
    115 on at
    Re: How to see if str2Enum returns nothing

    Try this:

    static void Test(Args _args)
    {
      ABC  abc;
      str test;
        ;
       test = "A";
       if(str2Enum(abc,test) == ABC::A)
       {
         print "test";
         pause;

       }

    }

  • Suggested answer
    Community Member Profile Picture
    on at
    Re: How to see if str2Enum returns nothing

    Hi Jonas,

    Are your intentions to just see if an enum exists?  If so use this global enum method instead of str2enum.

    static void Job35(Args _args)
    {

        NoYes ny;
        ;
        ny = enumName2Id("Baddy");
       
        if(ny > 0)
            info("Good enum");
        else
            info("Bad enum");

    }

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,001 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,837 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans