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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to pass enm values and int64 from soapservice to d365fo?

(0) ShareShare
ReportReport
Posted on by 1,552

My service is to create a customer So if my requestContractClass has this:

[DataMemberAttribute]
    public DirPartyType DirPartyType(DirPartyType _dirPartyType = dirPartyType)
    {
        dirPartyType = _dirPartyType;
        return dirPartyType;
    }
    
    [DataMemberAttribute]
    public int64 NameSequence(int64 _nameSequence = nameSequence)
    {
        nameSequence = _nameSequence;
        return nameSequence;
    }
    

i want to pass dirPartyType and NameSequence

if in C# i do the following:

CallContext callContext = new CallContext { Company = "contoso" };
var request = new requestContract();
request.DirPartyType = "Person";

i will get an error that an enumDataMember should be added, is there a way to pass an enum in c# instead of hard coding because i can't add enumDataMember in D365

1. is the only way is to make my request of type str instead of DirPartyType and in the service class do str2enum?

if(str2Enum(DirPartyType::Person,contractRequest.DirPartyType()) == DirPartyType::Person)
{
    custTable.insert(DirPartyType::Person,contractRequest.Name());
}

2. As for the nameSequence, u know in D365 it's a recId but it appears in the table as sth like "FirstMiddleLast"  so how can i pass the value instead of recId when i insert in the dirPerson.

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    1. I would use string here. That's the easiest solution and this way your C# code can support also new values in that enum easily. This is how it works in data entities, too.

    Just make sure that in export you provide the enum option name, instead of enum option label in user's language. That way it will not change even if users with different language settings use the service.

    2. Your service should accept it in string format (such as FirstMiddleLast). When you have that value, just use find method of DirNameSequence to get the record and RecId that you need. Also I suggest to add first name, middle name and last name as separate methods in your service. 

  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    Look at the type of request.DirPartyType property. I think it's an enum and you should use this enum instead of a string.

    Note that "i will get an error that an enumDataMember should be added" doesn't make clear whether you get a compilation or a runtime error and what the error exactly says. This makes it harder for us to help you.

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi JuniorAx,

    Can't you add default parameter for FirstMiddleLast in D365 and use it instead of passing this information from outside?

    To workaround enum issue, you can create 2 service methods createPerson, createOrganization and inside D365 you can call common method to create needed records.

  • junior AX Profile Picture
    1,552 on at

    Hi Nikolaos,

    1. what do u mean by export, this is an inbound service, so where would i want to use enumOptionName, can u explain more?

    2. what do u mean by putting FirstName,LastName and MiddleName in seperate methods? and u mean in c# code or in x code?
    All i do in c# is say request.NameSequence = "FirstLast"; request.FirstName = "first"; request.lastname ="last"; request.middlename = :" middle"; So can u explain?

    3. currently here's my x code , below when i update dirPersonName, i get this error:

    pastedimage1588775990974v2.png

    NumberSeq numberSeq     = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
                custTable.AccountNum    = numberSeq.num();
                custTable.CustGroup     = request.CustGroupId();
                custTable.OneTimeCustomer   = request.OneTimeCustomer();
    
                if(str2Enum(DirPartyType::Person,request.DirPartyType()) == DirPartyType::Person)
                {
                    custTable.insert(DirPartyType::Person,request.PartyName());
                }
                else if ( str2Enum(DirPartyType::Organization,request.DirPartyType()) == DirPartyType::Organization)
                {
                    custTable.insert(DirPartyType::Organization,request.PartyName());
                }
                else
                {
                    throw  error ("invalid dirPartyType");
                }
    
                DirPartyTable dirPartyTable;
                select dirPartyTable where dirPartyTable.RecId == custTable.Party;
                if(dirPartyTable is DirPerson)
                {
                    DirPerson dirPerson;
                    DirPersonName dirPersonName;
                    select dirPerson where dirPerson.RecId == dirPartyTable.RecId;
                    if(dirPerson)
                    {
                        if(DirNameSequence::find(request.NameSequence()).RecId != 0)
                        {
                            dirPerson.NameSequence = DirNameSequence::find(request.NameSequence()).RecId;
                        }
                        //dirPerson.PersonalTitle
                        select forUpdate dirPersonName where dirPersonName.Person == dirPerson.RecId;
                        if(dirPersonName)
                        {
                            dirPersonName.FirstName = request.FirstName();
                            dirPersonName.MiddleName = request.MiddleName();
                            dirPersonName.LastName = request.LastName();
                            dirPersonName.update();
                        }
                    }
                }
                else if (dirPartyTable is DirOrganization)
                {
                }

    Hi Martin,

    it should be enum but if i look at the type it says string, However if i use a base enum with Extensible: False, it will appear as enum. The error i get is this

    pastedimage1588774353086v1.png

    i took the error screenshot from this link who had the same issue: community.dynamics.com/.../enum-problems-in-d365fo-when-creating-custom-services

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

    1. If you don't export, then ignore it.

    2. In your first message you have data member for "Name". I suggest having separate data members for first, middle and last names. So, I mean C# and D365. There's no reason why you should combine the three pieces of data into one before inserting it in AX.

    3. Are you familiar with valid time state framework? Please check the documentation: docs.microsoft.com/.../valid-time-state-tables-and-date-effective-data

    It means that if you update the name, you need to decide if you want to update the existing name, or add new name that is valid from certain date (usually "now").. For example if someone gets married or divorces, their official name might change. People can just change their name if they feel like it. But before that change the name was something else, and you might want to store the old and new one. But you should discuss with your organization how they want to have it. I recommend setting the new name to be valid from now (or some other timestamp) but not changing the historical data. It might even be legally regulated like that in your country, so please check that too.

  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    Aha, so it's about an extensible enum. Unlike classic enums, extensible enums aren't implemented as managed enums under the hood and it seems that serialization logic wasn't updated to support them.

  • junior AX Profile Picture
    1,552 on at

    Hi sergie,

    I like the idea of creating a new method for each dirPartyType so thank you :)

    As for the default parameter, it's an inbound service so the user should be able to decide the sequence..right now when i say custTable.Insert(DirPartyType::Person); the Name sequence is filled automatically to "FirstMiddleLast" but i thought what if they want to change it when creating the customer, that's why i added it as a parameter.

    Hi Nikoloas,

    2. The name was for the DirPartyName, i have other fields called FirstName, Middle and Last.

    3. As i meantioned the service is used to create a customer, so when i write custTable.Insert(DirPartyType::Person), a dirPerson record  and DirPersonName is inserted automatically with empty FirstName, Middle and Last. That's why in my code i select the created record for update to fill these values. So i think based on my scenario there is no old name that i want to keep so what should i do to remove the error? I don't think there a property on the table i should change, there should be sth to do just for my service code to work, can u help?

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

    About question 3, please see the doc that I shared earlier. One subpage tells different ways to update records: docs.microsoft.com/.../effects-of-valid-time-state-tables-on-read-and-write-operations

    But I think you are doing something sub-optimally if you need to update the record that you just created. Perhaps you can look at the Customer creation form and underlying code in AX and find an easier way. I don't think you need to write direcly to DirPersonName at all.

  • junior AX Profile Picture
    1,552 on at

    .

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 669 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 449 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 384 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans