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

Address not created for customer in x++

(0) ShareShare
ReportReport
Posted on by 1,552

So i'm trying to create a customer with it's address by code, The address is no created, any idea why??

First i created a dirPerson record, then i did the following: (the dirPartyPostalAddressView recId is empty);

NumberSeq numberSeq         = NumberSeq::newGetNum(CustParameters::numRefCustAccount());
            custTable.AccountNum        = numberSeq.num();
            custTable.Party             = dirPartyTable.RecId;
            custtable.insert();
            
            container roles;
            roles = conIns(roles, 1, LogisticsLocationRole::findBytype(roleType).RecId) // assume roleType is Business
            
            DirParty dirParty;
            dirParty      = DirParty::constructFromCommon(custTable);
            
            dirPartyPostalAddressView.LocationName      = "location";
            dirPartyPostalAddressView.Street            = "street";
            dirPartyPostalAddressView.City              = "city";
            dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView, roles);

I have the same question (0)
  • Suggested answer
    Rahul Mohta Profile Picture
    21,032 on at

    first have location id  created with all address details and then use the location id to assign on customer

  • junior AX Profile Picture
    1,552 on at

    how to create locationId? number sequence? it's for logisticsLocation right? so i need to say DirPostalAddressView.Location = number sequence? (there is location which is int64 not locationId)

  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Just a suggestion, why not use CustCustomerV3Entity to create the customer? This way you wouldn't have to worry about any of the stuff that you are now spending time and money with (with this question and the others that you have posted).

    You can use data entities in code just like tables, so it's very easily to populate all required data and then insert it.

  • junior AX Profile Picture
    1,552 on at

    Hi Nikolaos,

    1. i started looking at this data entity. But i will still use custom service while using it, is that ok? (i mean not Odata)

    i will still say entity.field = request.field() //where request is the contract class

    2. i know in Odata there is no need for contract classes, but how i'm going to fill entity.field? i mean now in c# i define the request and give values to it's fields and in x++ i say entity.field = request.field()

    but in Odata, what will i define in c# if i'm not going to use contracts and what i'm going to say in x++? entity.field = what??

    2.  There are few fields that i need help with, can i fill them using this entity?

        a) Person BirthDate

        b) Description field in LogisticsLocation

        c) logisticsLocationRoleType

        d) Name field in TaxVATNumTable (i knw this table is not in the entity but how can i insert this field,

            am i going to do changes to the entity)?

    3. I want to create bankaccountAddress for my customer, how can i do that using this entity? or can i now continue this part with coding?

    4. I also want to create contactPersons for the customer and create addresses(postal and electronic) for each contactPerson... so i think this can't be done by dataEntities right? so if i switch to coding now, i will still have an issue with creating the addresses exactly as the issue i mentioned in the question. So please advise?

    5. If i added a new field to custTable, that i want to insert, then i need to create a new dataEntity since extension is not supported, then put CustCustomerV3Entity  inside my new entity? and create a new staging table that has all fields CustCustomerV3EntityStagingTable in addition to my new field? OR can i get the custTable record created from the entity and then update the record with the new field value?

  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    1. Yes, you can use entities from any x++ code

    2. You still need your contract class. But you can forget DirParty, DirPerson and others. Just populate the entity buffer in your x++ code to create customer. What fields are / are not available in the entity I leave for your detailed check. If some fields are missing, you can add them via extension or handle some other way. For example you can create TaxVATNumTable before inserting the customer.

    3. You can export data via the entity to see what the Organization info looks like. Then use your learning to insert data.

    4. Bank accounts are not part of customer entity. You can find related entity and use it, or not use entity for it. Entity or not, you still use coding.

    5. Contact persons have their own entities, please check them.

    6. You can add new fields to data entities via extension. What do you mean by "extension is not supported"?

  • junior AX Profile Picture
    1,552 on at

    2. If i keep using the customService and use this dataEntity then there is also no need for DirParty and others as they are inserted automatically, so if i make in the contract class a parameter of this DataEntity, will i be able to call every field in the DataEntity in c#?? if yes then what is this different than Odata, and if no, then i still need to define every field in the data entity as contract parameter and in x++ say entity.field = request.filed(); ??

    for the fields i'm asking about, i can see for example logisticsLocationEx dataSource that's why i'm asking if these fields exist, maybe they do but i can't find the name. Also i can find a field for BirthDate but it's _IT, also there are fields called personbirthDay, personBirthmonth in the datasources but they are not put in the dataEntity fields so maybe i should just drag them.

    and for that vat , i think it's not related to the customer, so i can create it anywhere

    4 &5 i'll check these data entites

    6. yeah they are supported, i tried first but i didn't have the extension option now it's back.

    If a field is in one of the dataSources of the entities, but not in the fields of the dataEntity, when i drag it to the fields do i need to update Staging Table?

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

    2. You are free to do whatever you want. I'm lazy so I personally would try to minimize work and cost, and keep the current contract class. And only handle the entity inside D365 x++ code. "How it's different from OData"? Well, you are developing a custom service where part of the creation is handled by the entity data model. In OData you work only with data entities, one at a time. And of course the technical solution of communicating with OData endpoint vs. custom service endpoint is a bit different.

    6. All fields that you add to the entity must be added to the staging table as well.

  • junior AX Profile Picture
    1,552 on at

    ok just to make things clear

    1. Now in custom Service, for example if i remove Street and City Parameters

    and add CustCustomerV3Entity parameter.

    in C# when i define the contract class, how i'm going to get to the CustCustomerV3Entity.AddressStreet and CustCustomerV3Entity.AddressCity and fill them?

    2. In Odata, does it seems like there won't be any logic in x++? i only need to define the entity in c# and fill it's fields? and what to do if i want to fill sth not related to data entities, for example the TaxVatNum where do i do this .. in c# or x++. I'm asking this because in custom service there was an x++ service class that get's called from c#. But in Odata what class do i call from x++?

    3. Based on my scenario do u see that it's better if i stick to custom service or it will work with  Odata?

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

    1. You need to have some kind of contract class. Either it contains your current methods / variables, or you create a new class that contains the fields from the entity. Data entity is purely a Dynamics concept and you can't expose it as a parameter in the service. So you still need to have parameters like Street and City

    2. In entity, you can add logic in postLoad method (for export) or mapEntityToDataSource (for import).

    3. I don't know why you chose custom service, and I don't know much about your scenario so I can't recommend anything at this point.

    Why did you choose custom service?

  • junior AX Profile Picture
    1,552 on at

    2. But here in Odata i don't need parameters for street and City right?

    and why i can't put my extra logic in custom service here in post load of the dataEntity i'm using, or the post load will only be called if i use oData?

    3. To be honest, when i started i didn't know anything about custom services or Odata  so i first started learning about custom services, that's why i chose it. And now my scenario is to create a customer with it's (postal and electronics addresses) , creating customer Bank Account address and creating contactPersons for this customer with (postal and electronic address) for each contactPerson. In general to create customer with extra details. So what do u think? would it work in Odata? if yes is there any disadvantage to keep using the custom service? or what are the advantages if i switch to Odata?

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
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans