Having referred couple of videos on AL with JSON and reading 1-2 community Q&A here, I still haven't figured out the correct way to read multiple line items from a Invoice record, which is being fetched into Business Central via an API.
Notes:
1. Read from the Response text, the first node, which starts with 'list', Invoice header is entered successfully
2. Each header now has multiple "line_items" associated
3. For some reason, my AL code is unable to fetch/read/recognize "line_items" array from the Response Text, but successfully recognizes "list" array. Only the header record in BC is created successfully with no lines associated
Present Outcome: Can read & insert header values, but cannot locate/read line values from the API, due to nested API
Expected Outcome: To be able to fetch each line_items "ID" and corresponding line_items data in a loop and insert all the line_items values into a table, whenever each/single header is inserted
Below Images showcase, 1-2 AL code trials which I have conducted, all with no positive results. Also pasted image of the Incoming JSON structure
I know I am doing something incorrect, either logically or syntactically. Community, please advise / assist
Stefano Demiliani waldo Marco Mels ajkauffmann yzhums Nitin Verma
Thankyou Arend-Jan, you are a superstar as always. I spent a couple days debugging on this silly logic error
You are pretty close.
Function CreateSalesDocuments(TransToken, CGBSalesHeader) receives the JsonToken that holds the invoice. You are already reading the id with 'invoice.id'. The array of line_items can be retrieved with TransToken.SelectToken('invoice.line_items', JsonToken).
Then use JsonToken.AsArray() and loop through the resulting array.
Hi,
Try to read and consume as per below request I did.
if not JToken.ReadFrom(serviceResponse) then
|
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,524 Super User 2024 Season 2
Martin Dráb 228,469 Most Valuable Professional
nmaenpaa 101,148