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

simplifying custom service

(0) ShareShare
ReportReport
Posted on by 1,552

So i'm creating a custom service to create a customer with it's postal and electronic address. Also I need to create contactPerson for that customer (so my contract class has data members related to custTable,ElectronicAddress and postal address fields. In addition to List of ContactPerson as well which is another contract class for the contractPerson) and i want to create  postal and electronics address for each contact

So Currently I'm making contract class data members for each field i want to insert in addition to the listContractPerson

Imagine with me when trying to call the service from c#

i need to fill in c# some DirPartyTable fields ,some DirPerson fields , some DirPersonName fields and some custTable fields (Assuming i'm creating a person type)

so for these i might have about 20 data members ( i also need to do in x++ field = request.sth() about 20 times)

now when i create address for this customer i need to fill fields related to logisticsPostalAddress, logisticsLocation and electronicAddress (also maybe another 20 data members)

But now when i create contactPerson, ( as i said i made a new contract class for this one) let's say i want to create two contact Persons for that customer, so when i create address for each one, then i need to duplicate the data. I mean in c# i need to insert data for ContactPerson1 and ContactPerson2 (maybe there is 10 fields for each one) and in x++ it will be a while loop.

is that normal? I'm feeling like maybe there can be a simpler way? I read that entities can be used but i didn't get it, i mean instead of writing field = request.sth(), what will i write? is there anything that can make things simplified?

 

I have the same question (0)
  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi JuniorAX,

    Have you considered using oData to create records in D365 instead of custom service?

  • junior AX Profile Picture
    1,552 on at

    Hi sergie,

    Is it going to cover my scenraio.. Which is creating a customer with it's addresses and list of contact person with it's adresses?

    I never used oData.. So how is it going to make it simplified.. I'm still going to fill each field in c# and how i'm going to deal with in x++? Am i nit going to say field1 =value inserted from c#? 

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Junior AX,

    D365 already has a list of standard entities which will cover your scenarios. If you don't have a lot of customization in this area you don't need to do any customizations in D365 to create customer with addresses and contract persons.  

    You can take a look how to work with oData in the same example project from GitHub github.com/.../Dynamics-AX-Integration

    Examples are placed in ODataConsoleApplication project.

  • junior AX Profile Picture
    1,552 on at

    I will give it a try but i'm not sure if i have time to switch the whole process right now.

    May i ask why would Odata be better in this case, what would it save me?

    i just looked at the example, correct me if i'm wrong, but does it seem that in D365, the only thing i need to do is create dataEntites or use existing ones, and then do all the logic in c#( i mean inserting fields).. it seems that save changes method will insert records into the tables in Data Entities?

    while in custom service i have to do contracts and in x++ i had to say that each field = the field from c#?

    so here i had to say table.field = request.field in addition to the contracts classes

    while in Odata, no need to do any logic in x++ and directly in c# say entity.field = "UserInput".

    is that the difference? and how would i define the data entities i want to use?

  • Suggested answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    It seems that you're not aware of F&O documentations. There you can find answers to many of your questions - for example. look at Data entities overview and Build and consume data entities.

    A huge difference between custom services and data entities is that you must design contract classes with all fields in case of custom services. No such work is needed for data entities / OData services. Also, data entities automatically handle table references, foreign-key replacements, call table methods etc. - you don't have to implement such things by yourself. And there are many existing data entities with all necessary business logic.

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 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans