Skip to main content

Notifications

Community site session details

Community site session details

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

insert not allowed for field 'OrderTotalChargesAmount' when creating sales order through odata

(0) ShareShare
ReportReport
Posted on by 2,426

Hi,

when i am trying to insert sales order through console application by calling odata end point (SalesOrderHeaderEntity).

i am facing this error

"insert not allowed for field 'OrderTotalChargesAmount'"

I saw in entity level as this field has allow edit , allow edit on create - no.

How can we resolve this.

Skipping this field in mapentitytodatasource(), initializeEntityDatasource() is the correct way.

Please show some light on this,

Regards,

Have a nice day

  • AX 2012 r3 Profile Picture
    2,426 on at
    RE: insert not allowed for field 'OrderTotalChargesAmount' when creating sales order through odata

    Hi Gunjan,

    I found solution for this.

    I use this piece of code

    context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset);

    savechangeoptions.postonlysetproperties - Which will avoid setting null values.

    Now that ordertotal amount error is gone now and now i am getting mandatory field errors which i will fill add fields to entity and will try to insert.

    Regards,

  • AX 2012 r3 Profile Picture
    2,426 on at
    RE: insert not allowed for field 'OrderTotalChargesAmount' when creating sales order through odata

    Hi Gunjan,

    Please check this

     SalesOrderHeaderV2 soh = new SalesOrderHeaderV2();
                    DataServiceCollection salesOrderCollection = new DataServiceCollection(context);
                    salesOrderCollection.Add(soh);
    
                    soh.SalesOrderNumber = salesOrderNumber; // Change number sequence setting in AX to allow user to set values.
                    soh.CurrencyCode = "USD";
                    soh.InvoiceCustomerAccountNumber = "US-003";
                    soh.OrderingCustomerAccountNumber = "US-003";
                    soh.LanguageId = "en-us";
                    soh.DataAreaId = "USMF";
                    
                    context.SaveChanges();

    Please show light on this

    Regards,

    Have a nice day.

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: insert not allowed for field 'OrderTotalChargesAmount' when creating sales order through odata

    Hi,

    Could you please share the code you are using?

  • AX 2012 r3 Profile Picture
    2,426 on at
    RE: insert not allowed for field 'OrderTotalChargesAmount' when creating sales order through odata

    Hi gunjan,

    Hope you are fine.

    i have tried SalesOrderHeaderV2Entity now i am getting different field

    'OrderTotalAmount'

    I am not entering any value for this field.

    This field is also having allow edit , allow edit on create - no.

    Please show some light on this.

    Regards,

    Have a nice day.

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: insert not allowed for field 'OrderTotalChargesAmount' when creating sales order through odata

    Hi,

    What version of D3FO are you on?

    In the current version, SalesOrderHeaderEntity is obsolete. You should use SalesOrderHeaderV2Entity instead.

    Secondly, are you trying to set this field while inserting into the entity? This belongs to SalesOrderTotals table, which is marked as  a ReadOnly data source in the entity. You can read from this table, but can't write into it.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,060 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,858 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans