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

Odata

(0) ShareShare
ReportReport
Posted on by 1,552

I never worked on services in AX12 but i have few questions.

From what i read, is there used to be standard services for example to create customer.

Now in D365Fo if i want a service to create a customer

1) should i look for data entity that is related to a customer and make it's property public then use Odata? 

2) if i want to do custom things i can write code in post load and this will work too? or i should write code in c#?

3) is it correct that i chose odata instead of custom service in this case and why?

4) when i should use custom service instead of odata? and how to decide which one is best? will both of them work?

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

    In AX2012 you already had AIF, custom services and DIXF (Data Import Export Framework).

    Now you have OData, DIXF (Data management) and custom services.

    1) You can't any existing (Microsoft) entities to public unless they are already public. But the customer information entity is public. Then you can use the entity via OData or data management projects

    2) You can add custom logic via x++. PostLoad is executed in export of data, mapEntityToDataSource is executed in import

    3) You choose the approach that fits best. For customer integration I recommend using entities instead of custom service, but with entities you still have to choose between OData (real time) or Data management project / Data package API (batch based)

    3) (you have nr 3 two times) please check this: docs.microsoft.com/.../integration-overview

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

    Yes, you can use public data entities to query, insert, update and delete records via OData services. The entity for customers is already public, therefore you can simply use it. You can't modify the Public property anyway (but you can set it when creating new entities).

    "To do custom things" is a very generic term. postLoad() can be used to populate for so-called virtual fields, e.g. fields that don't exist in database and their value is set only in X++ code.

    While data entities are primarily used to perform CRUD operations (Create, Read, Update, Delete) on documents (customers, orders...), custom service are used for remote procedure calls. You design a method accepting some parameters and/or returning a value and expose this method as a web service operation. You design everything by yourself, which gives you more flexibility, but if you wanted to reproduce the functionality of data entities, you would find that data entities do a huge amount of work for you. Data entities are also used for other purposes, such as data imports, exports to BYOD and so on.

    Note that OData also supports actions on entities, which are a bit similar to custom services.

  • junior AX Profile Picture
    1,552 on at

    Thanks nikolas and Martin

    1) i think if a data entity is not public i can create a new data entity that contains the original one and make it public

    2) so let's say in the post load i put virtualfield1 = field2*field3.. if i want to change it's value when an external system call d365Fo then i need to change the value using c#? So in c# i should write all the logic i want the external system to do when trying to insert in d365fo but in postLoad and other methods i put a general logic that i want always to work?

    3) So if i only want to do CRUD operations, it is recommended to use Odata but it's not wrong to use custom services? and can u give me a simple example related to the customer service that will make me switch from odata to custom service?

    4) if i want to insert to customer table and other related tables to the customer like dirParty,logistics postal, etc... then it's still better to use a data entity that has joins to these data sources instead of custom service?

    5) i didn't get what you mean by actions? what a custom service can do that a data entity can't?

    6) if a service in AX12 used a custom service then if i want to do a similar thing in d365fo then i should use the same procedure they used which is a custom service?

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

    1) Yes, that's correct

    2) I don't understand the question. If you have virtual field which is calculated based on two actual fields you will get an up-to-date value every time when you read this entity. There's no C# involved anywhere. If you want some code to be executed when the entity is read/written you write this code in the entity with x++.

    3) Not necessarily OData. With large volumes you should use DIXF/Data management. OData has quite poor performance.

    4) It's easier to use the entity than model everything from scratch in your custom service

    5) Entities can have actions = some business logic related to the entity record. But all entity-related stuff is always related to the entities (and one record at a time) such as customer, sales order etc.  With custom services you have ability to run any kind of x++ business logic. If you already have some idea when to use AIF in AX2012, and when to use custom services, I would say the distinction is still pretty much the same in entities vs custom services of D365FO

    6) Yes, it's pretty much the same.

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

    2) In your case, setting the value of virtual field makes no sense. Normally you can read the virtual value and process it in mapEntityToDataSource() (you can find an example in documentation), but here you wouldn't know how to divide the value to field2 and field3.

    4) Definitely. Otherwise you would have to design and maintain (think about adding a field to the table) the data contracts and implement all related logic.

    5) Here is a link to F&O documentation page briefly talking about OData action. It should give you an idea. As I said, OData are about entities. Custom services can do whatever you want (but it does nothing for you; you must implement everything by yourself).

    6) It's likely that you'd use a custom service as well, but I would still review whether you can benefit from new features of F&O.

  • junior AX Profile Picture
    1,552 on at

    1) sorry i meant mapEntityToDataSource() method. when i searched the net i saw that they write code in c# to insert a a new customer (where they say customer.field1 = , customer.field2 = etc...) I must use c# to insert a a customer or can i do that in x++? if yes where in x++ ? that's why i told u if i want to change a field value to sth different when inserting the record other than the logic written in mapEntityToDataSource() then  i have to do it in c# (Assuming that the case where i want to change the field value is valid) 

    stoneridgesoftware.com/.../

    2) DIXF is for file based integrations (i don't want that) and if you mean batch by Data management then this is not my case i want real time

    3) since i can use actions, it seems that i can always use odata instead of custom services. I know this is not correct but i need an example that shows me that it's wrong to use odata and i have to use custom services?

    4) In ax 2012, i think they could reference standard service (AIF) in their custom service. I mean if you want to do extra things in addition to creating customer, then you can reference that AIF in your custom service am i correct? if yes can i use Odata in my custom service as well?

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

    1. When you see C# code they are examples on how to call D365 OData endpoint from C# application. You can call the OData endpoints from many/any programming language, also C#. But it has nothing to do with customizing the entities. But YES, if you want to call the OData endpoint from external non-x++ application, you must use other language than x++ :)

    3. You use custom services when you want to run some logic that is not linked to any entity. Via custom service you can execute any x++ logic. Via data entity you can execute logic that is related to that entity (and single record). Most likely if you can't figure out why you should use custom services, then you should not use them.

    4. No, you can't use OData in custom service. But of course you can use data entities in x++ code, including in your custom services.

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

    It seems that you started new numbering...

    1) You can consume OData services in other applications, such as something written in C#. There you can assign values to fields, but it's exactly the same whether they're virtual or not. The caller doesn't know these implementation details.

    3) Please check out previous replies.

    4) You can use data entities (not OData) in any X++ code, in the same way as you use table. Therefore yes, you can use them from custom services as well.

  • junior AX Profile Picture
    1,552 on at

    1) so if in data entities  i can only execute logic that is related to the data entity, does that mean in oData actions i can only write logic related to the entity? i can't for example write code to post a sales invoice? if i can then i still can't differentiate when to switch to custom services instead of Odata

    2) so if i created an odata to insert customers, then i got a new task to create a service to insert customers and do other logic that requires me to use custom services instead of odata, does that mean i have to re-implement the logic of creating a customer using custom services in addition to the other new logic because i can't odata in custom services?

    Thanks a lot both of you

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

    1) Posting a sales order sounds to me like something related to the sales order entity. You could use a custom entity, but you can also use an OData action. But if you want information about the current session, for instance, it's not related to any data entity.

    2) No, I did say that you can use data entities (and therefore all logic encapsulated in data entities) from your X++ code in custom services. You just have no reason for using OData service - they're used to call F&O from outside, but your code already runs inside. You simply refer to an entity in X++ by its name.

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans