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 :
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

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

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

    }

  • somvir gahlawet Profile Picture
    115 on at

    Try this:

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

       }

    }

  • Suggested answer
    Denis Patrakov Profile Picture
    on at

    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.

  • Tommy Skaue Profile Picture
    Moderator on at

    So basically this works:

    static void Adtest_enum(Args _args)
    {
        NoYesCombo      n;
        ;
        if (!enum2str(str2Enum(n, 'bad')))
        {
            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

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Sukrut Parab Profile Picture

Sukrut Parab 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans