Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

OData - Create a LedgerJournalHeader and Lines in one POST request

(0) ShareShare
ReportReport
Posted on by 20

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.


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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February 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... 293,110 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,886 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans