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, ...
Answered

enum2str not working correctly

(0) ShareShare
ReportReport
Posted on by 1,552

Hi,

So i created a custom service, and when i try to call it from .net by doing the following:

DirPartyType = "Person" or DirPartType = "Per"

x code take it as person and my code enters the if statemenet that says dirPartyType::person. Why is that?

but if i try for example DirPartyType = "xx"  then i get invalid DirPartyType

Here's code in my service.

DirPartyType dirPartyType;
TestFactory::create(str2Enum(dirPartyType,_req.DirPartyType())


public static TestFactory create(DirPartyType _dirPartyType)
{
    if(_dirPartyType == DirPartyType::Person)
    {
        return new TestPCreator();
    }
    else if(_dirPartyType == DirPartyType::Organization)
    {
        return new TestOCreatorCreator();
    }
    else
    {
        throw error('Invalid DirPartyType');
    }
}

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    303,724 Super User 2026 Season 1 on at

    Hi Junior AX,

    Can you share where and how the service is validating or retrieving the party type value? The code you shared already has this value, I assume.

  • Verified answer
    Faisal Fareed Profile Picture
    10,796 User Group Leader on at

    Hi Junior AX,

    As per the MS document for str2Enum function (docs.microsoft.com/.../aa655065(v=ax.60)  Retrieves the enum element whose localized Label property value matches the input string.

    You have to use something like this;

    class Community

    {

       /// <summary>

       /// Runs the class with the specified arguments.

       /// </summary>

       /// <param name = "_args">The specified arguments.</param>

       public static void main(Args _args)

       {

           DictEnum dictEnum = new DictEnum(enumNum(DirPartyType));

           dictEnum.symbol2Value('PER');

           //DirPartyType dirPartyType;        

           //Community::create(str2Enum(dirPartyType, "x"));

           Community::create(dictEnum.symbol2Value('PER'));

       }

       public static void create(DirPartyType _dirPartyType)

       {

           if(_dirPartyType == DirPartyType::Person)

           {

               //return new TestPCreator();

           }

           else if(_dirPartyType == DirPartyType::Organization)

           {

               //return new TestOCreatorCreator();

           }

           else

           {

               throw error('Invalid DirPartyType');

           }

       }

    }

  • junior AX Profile Picture
    1,552 on at

    Hi Faisal,

    It worked, but may you explain what is the difference between using DictEnum and what i originally did? and what does symbol2Value do?

    Hi Andre,

    in.Net i'm calling the service, by filling the contract parameters

    request.Customer = new customerContract()
    {
        CustGroupId = "group",
        TaxGroup = "tax",
        //DirPartyType = "Per"
        DirPartyType = "Person"
    };

    and as i mentioned in the code before, the value i filled in .Net is saved in _req.DirPartyType(), so i took this value and i passed it to TestFactory class

    DirPartyType dirPartyType;
    TestFactory::create(str2Enum(dirPartyType,_req.DirPartyType())

    and again here's the test factory class:

    public static TestFactory create(DirPartyType _dirPartyType)
    {
        if(_dirPartyType == DirPartyType::Person)
        {
            return new TestPCreator();
        }
        else if(_dirPartyType == DirPartyType::Organization)
        {
            return new TestOCreatorCreator();
        }
        else
        {
            throw error('Invalid DirPartyType');
        }
    }

  • junior AX Profile Picture
    1,552 on at

    Hi Faisal,

    I started getting this warning using your way:

    Warning Assigning a numerical value to extensible enum 'Extensible Enumeration(DirPartyType)' will yield unexpected results. Extensible enum values are not deterministically assigned to a numerical value.

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 658

#2
André Arnaud de Calavon Profile Picture

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

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans