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 - Create a LedgerJournalHeader and Lines in one POST request

(2) ShareShare
ReportReport
Posted on by 26

For a POC, I am trying to create a general ledger Journal Header + Lines via the ODATA service.

I can do this successfully by making multiple calls:-

- POST the header - get back the ID of the created record (BatchNumber)

- POST each LedgerJournalLine item, this needs the batch number set as a foreign key which I have obtained from above.

So for a general ledger journal that has 4 items, thats a total of 5 http requests (1 for header + 4 lines)

This is not ideal.

i can see that I can query for headers and include their lines in a single GET request using the $expand odata syntax.

```
https://your-org.trial.operations.dynamics.com/data/LedgerJournalHeaders?$filter=dataAreaId eq %27demf%27&cross-company=true&$expand(LedgerJournalLines)

```

I tried POSTing the following JSON payload - its the same Header payload that posted successfully on its own, but I've tried to set it's `LedgerJournalLine` navigation property with an array of lines to be included:

```

{
"dataAreaId": "demf",
"JournalName": "GenJrn",
"Description": "Posted by poc",
"LedgerJournalLine": [
{
"dataAreaId": "demf",
"ReverseEntry": "No",
"ItemSalesTaxGroup": "FULL",
"CashDiscountDate": "1900-01-01T00:00:00Z",
"Text": "Test",
"OffsetAccountType": "Ledger",
"IsWithholdingCalculationEnabled": "No",
"ReverseDate": "1900-01-01T00:00:00Z",
"TransDate": "2022-12-16T13:38:15.8721698Z",
"DefaultDimensionDisplayValue": "",
"PaymentReference": "",
"Document": "",
"CashDiscountAmount": 0,
"ExchRate": 100,
"ChineseVoucherType": "",
"DebitAmount": 0,
"SalesTaxCode": "",
"DocumentDate": "1900-01-01T00:00:00Z",
"OffsetAccountDisplayValue": "",
"AccountDisplayValue": "618170-001--",
"CashDiscount": "",
"OffsetDefaultDimensionDisplayValue": "",
"SalesTaxGroup": "",
"AccountType": "Ledger",
"Invoice": "",
"DueDate": "1900-01-01T00:00:00Z",
"ReportingCurrencyExchRate": 0,
"PaymentMethod": "",
"PaymentId": "",
"PostingProfile": "",
"ExchRateSecond": 0,
"CreditAmount": 100000,
"OverrideSalesTax": "No",
"OffsetCompany": "demf",
"Quantity": 0,
"ItemWithholdingTaxGroupCode": "",
"TaxExemptNumber": "",
"ReportingCurrencyExchRateSecondary": 0,
"CurrencyCode": "EUR",
"Company": "demf",
"ChineseVoucher": "",
"DiscountPercentage": 0,
"OffsetText": ""
},
{
"dataAreaId": "demf",
"ReverseEntry": "No",
"ItemSalesTaxGroup": "FULL",
"CashDiscountDate": "1900-01-01T00:00:00Z",
"Text": "Test",
"OffsetAccountType": "Ledger",
"IsWithholdingCalculationEnabled": "No",
"ReverseDate": "1900-01-01T00:00:00Z",
"TransDate": "2022-12-16T13:38:15.8729043Z",
"DefaultDimensionDisplayValue": "",
"PaymentReference": "",
"Document": "",
"CashDiscountAmount": 0,
"ExchRate": 100,
"ChineseVoucherType": "",
"DebitAmount": -100000,
"SalesTaxCode": "",
"DocumentDate": "1900-01-01T00:00:00Z",
"OffsetAccountDisplayValue": "",
"AccountDisplayValue": "618170-001--",
"CashDiscount": "",
"OffsetDefaultDimensionDisplayValue": "",
"SalesTaxGroup": "",
"AccountType": "Ledger",
"Invoice": "",
"DueDate": "1900-01-01T00:00:00Z",
"ReportingCurrencyExchRate": 0,
"PaymentMethod": "",
"PaymentId": "",
"PostingProfile": "",
"ExchRateSecond": 0,
"CreditAmount": 0,
"OverrideSalesTax": "No",
"OffsetCompany": "demf",
"Quantity": 0,
"ItemWithholdingTaxGroupCode": "",
"TaxExemptNumber": "",
"ReportingCurrencyExchRateSecondary": 0,
"CurrencyCode": "EUR",
"Company": "demf",
"ChineseVoucher": "",
"DiscountPercentage": 0,
"OffsetText": ""
}
]
}

```

When I do this I get Bad Request error with this message:

```

"message":"Cannot apply PATCH to navigation property 'LedgerJournalLine' on entity type 'Microsoft.Dynamics.DataEntities.LedgerJournalHeader'.","type":"System.InvalidOperationException","stacktrace":" at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataEntityDeserializer.ReadODataBody[T](HttpRequestMessage request)"
}
}

```

I know there is a seperate Batch api but that looks even more complicated to use, so I wanted to pursue whether it was possible to create a journal header and its lines in a single HTTP request without using that.


I have the same question (3)
  • CU26080734-0 Profile Picture
    2 on at
    Did you got anything on this?
  • Suggested answer
    Anthony Blake Profile Picture
    2,963 Super User 2025 Season 2 on at
    I think that the $Batch functionality is the way to go on this one unfortunately, its not easy to get working using Postman, but it much easier using the C# OData Connected Service as the batch functionality is built in so you just set some parameters in your code.
     
     
    Another old article, but take a look here for the OData Connected Service: https://community.dynamics.com/blogs/post/?postid=f4207895-68a2-41d5-9312-c85b917a5a1e

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans