Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / OData - Create a Ledge...
Finance forum
Unanswered

OData - Create a LedgerJournalHeader and Lines in one POST request

Posted on by 18

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.


Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,989 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans