web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to use odata for a create operation in d365?

(0) ShareShare
ReportReport
Posted on by 1,907

Hi,

I want to create sales order using odata

I've download Authentication Utility, odata utility and odata console application from Github

I've edited Auth utility with correct client Id and secret

1) what should i do with odata utility

2) what should i do with odata Console app

3) how to create a sales order using odata in console app

4) should i use sperate entites header and lines or can i use the composite entity

5) can biztalk call odata? And is there a better way for my scenario other than odata? 

I have the same question (0)
  • AnithaEswaran Profile Picture
    2,032 on at
    RE: How to use odata for a create operation in d365?

    Hi,

    You can use Postman to test the creation of SO.

    Set up of Postman and consuming odata entity is described in this blog

    anithasantosh.wordpress.com/.../

    For your 4th question, i used Header and Lines entity to create data in D365FO.

    Since Odata is exposed as service, BT can also consume Odata. Other options like Logic apps, Azure Data Factory can also be used to consume OData entities.

  • Martin Dráb Profile Picture
    236,513 Most Valuable Professional on at
    RE: How to use odata for a create operation in d365?

    1) Don't do anything with it - it's a library used by the actual application.

    2) Run the application to execute code samples. Modify the code of Program class to run another sample.

    3) First of all, look into SimpleCRUDExamples.cs. It should give you some idea - that's the whole point of this sample application.

    4) No, you can't use composite entities via OData.

    5) If nothing else, there is a commercial connector. Nevertheless that's a completely different topic, therefore please create a new thread if needed.

  • .. Profile Picture
    1,907 on at
    RE: How to use odata for a create operation in d365?

    Hi Martin,

    1) shouldn't i change the MetadataDocumentUri in dataUtility to my dev environment link? However when i did i got alof of errors

    2) when i kept document Uri the same then in data console app i found create sales order without changeset and it run corrctly but it didn't create an krder in my environment.

    What are the steps im missing

    I created another thread

    community.dynamics.com/.../1154518

  • Martin Dráb Profile Picture
    236,513 Most Valuable Professional on at
    RE: How to use odata for a create operation in d365?

    1) No, it's not needed to run the application. You would need that if you wanted to regenerate entity classes.

    2) I'm sorry, I can't identify your problem, because I know nothing about your code nor your environment. Review your code, then make sure you're connecting to the right environment and the right company. Review your logic for finding the new order. Then check logs. If nothing reveals the problem, it'll be time for debugging.

  • .. Profile Picture
    1,907 on at
    RE: How to use odata for a create operation in d365?

    Hi martin,

    I added a try catch and it seems i need to fill certain fields.

    However i noticed that data utility uses SalesOrderHeader instead of SalesOrderHeaderV2

    How can i make it connect to V2? Should i replace dataclient.cs file but it's very big is there something easier? 

  • Martin Dráb Profile Picture
    236,513 Most Valuable Professional on at
    RE: How to use odata for a create operation in d365?

    If you want to see an example of using OData, I think that SalesOrderHeader will do the job. Use SalesOrderHeaderV2 later, when you learn the basics and you'll create your own application, instead of playing with the sample application from Microsoft.

    You shouldn't change dataclient.cs by hand. It's generated code based on OData metadata (that's what MetadataDocumentUri is for).

  • .. Profile Picture
    1,907 on at
    RE: How to use odata for a create operation in d365?

    Hi Martin,

    I'm getting this error  for a certain field when using the standard SalesOrderHeader ( this field is not mine, it's customized (other model)) How to solve it?

    "insert not allowed for field 'CustomField'","type":"Microsoft.Dynamics.Platform.Integration.Services.OData.ODataSecurityException","stacktrace":

    Here's my code:

    public static void CreateSalesOrderInSingleChangeset(Resources context)
            {
                try
                {
                    SalesOrderHeader salesOrder = new SalesOrderHeader();
                    DataServiceCollection salesOrderCollection = new DataServiceCollection(context);
                    salesOrderCollection.Add(salesOrder);
    
                    //salesOrder.SalesOrderNumber = salesOrderNumber; // Change number sequence setting in AX to allow user to set values.
                    salesOrder.CurrencyCode = "GBP";
                    salesOrder.InvoiceCustomerAccountNumber = "Cust1";
                    salesOrder.OrderingCustomerAccountNumber = "Cust1";
                    salesOrder.LanguageId = "en-gb";
                    salesOrder.DataAreaId = "comp";
    
                    context.MergeOption = MergeOption.OverwriteChanges;
                    context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithIndependentOperations);
    
    
                    SalesOrderLine salesOrderLine = new SalesOrderLine();
                    DataServiceCollection salesOrderLineCollection = new DataServiceCollection(context);
                    salesOrderLineCollection.Add(salesOrderLine);
    
                    salesOrderLine.SalesOrderNumber = salesOrder.SalesOrderNumber;
                    salesOrderLine.ItemNumber = "item1";
                    salesOrderLine.OrderedSalesQuantity = 1;
                    salesOrderLine.ShippingSiteId = "0106";
                    salesOrderLine.ShippingWarehouseId = "Loc1";
                    salesOrderLine.DataAreaId = "comp";
    
                    context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); // Batch with Single Changeset ensure the saved changed runs in all-or-nothing mode.
                    Console.WriteLine(string.Format("Invoice {0} - Saved !", salesOrderNumber));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
            }

    2) Is using these two lines for creating sales order header and line together and using NumSeq is correct? cause currently it seems i'm saving twice one for the header and one for line.


    context.MergeOption = MergeOption.OverwriteChanges;
    context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithIndependentOperations);

    3) The reason i asked for SalesOrderHeaderV2 is because this custom field is not there. So i tried generating my own ODataClient.tts

    I created it from wizard. Where i filled:
    ublic const string MetadataDocumentUri = "D365FOURL/data/$metadata".

    and  public const string TempFilePath = @”C:\Temp\Edmx.xml”

    However i got those two errors

    pastedimage1618349727143v4.png

    any idea how to solve them?

  • Martin Dráb Profile Picture
    236,513 Most Valuable Professional on at
    RE: How to use odata for a create operation in d365?

    This thread is very confusing, because you're trying to discuss ten different things. Each of tem requires separate discussion and its own status (answered / unanswered) and mixing it all together makes it difficult.

    Please create separate threads for your new questions and provide enough details for each of them. For example, in your last problem, it's not clear why you changed both values and what data you put to the Edmx.xml file.

  • .. Profile Picture
    1,907 on at
    RE: How to use odata for a create operation in d365?

    Hi Martin,

    You are right, i will create two other threads. Thank you

    1. community.dynamics.com/.../how-to-create-an-order-header-lines-using-c-odata

    2. community.dynamics.com/.../how-to-create-my-own-odatautility

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,841

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 490 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans