[BC24] Trouble with advanced Deep Insert using an API page

FerroFerro Member Posts: 9
edited 2024-10-04 in NAV Three Tier
Hello all,

I had this customer requirement to implement in BC24 OnCloud:

Create a new sales order + sales lines using the same API call. This works and the response returns all the information that was created successfully (Both information about the Header and the lines).
I used the REST API URL to deep insert this document and made a copy of Microsoft's APIV2 pages regarding sales documents (Page 30028 "APIV2 - Sales Orders" and Page 30044 "APIV2 - Sales Order Lines").

However, the requirement changed. Now I need to be able to:

Insert the Sales Header
Inser the sales lines
After inserting each Sales Line I have to create X amount of vouchers on another table. (I wrote code on the OnInsert trigger of the Sales Line table so this is done through code).
Return all information including these vouchers (related to that Sales HEader document) created during the API call (in the JSON response).

All in the same API call!

I'm relatively new to this API shenanigans and frankly multiple deep inserts are still a bit overwhelming.
So I ask, is this even possible?
Or should I tell the customer to separate some functionalities?


Thanks in advance.

EDIT: We opted for separating the Insert and create logic from the return logic. So the customer will have to consume the API page and insert the sales order and then my code will create X amount of vouchers (In the same call).

Then they'll have to call the same API page but with GET method and ?expand parameter to get all the info they need.

Answers

  • Developer101Developer101 Member Posts: 532
    So all has worked in the end ?
    United Kingdom
  • FerroFerro Member Posts: 9
    So all has worked in the end ?

    More or less. The customer wasn´t too happy about this approach but we told him it was Microsoft API's standard behavior.
  • Developer101Developer101 Member Posts: 532
    What was wrong with the initial approach? Did you try it first and see if it has worked?
    United Kingdom
  • FerroFerro Member Posts: 9
    I don't know if anything was wrong or if it was even possible to do what I asked before. I tried many ways to try and get the voucher information returned in the JSON response in postman but it always came empty.

    It works fine if you send SalesHeader -> SalesLines -> Voucher information in the JSON request. But I can't do that. Each voucher entry must be created after inserting each Sales Line through the API page. So I'm using the trigger OnInsertRecord(BelowxRec: Boolean): Boolean of the SalesLines API.

    As I understand it, If you send a JSON request with Sales Header fields, you will receive a JSON response with the Sales Header fields that were sent (an so on...), since I'm not sending the voucher block in the JSON request I'm also not receiving them in the JSON response...
Sign In or Register to comment.