cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Set Batches for child items of a Sales BOM Item in SAP B1 SDK

saadsabri
Explorer
0 Kudos
1,410

Dear all

I am facing a challenge where I have to make an A/R Invoice document (through SAP B1 DI API) with some items that have a Sales BoM (Non Inventory Item) and some of the child items of these parent/BoM items are batch managed.

In case of NON-BATCH items, I would just have one line in the document and set parent item code and post the A/R Invoice and it automatically fetches and sets the child items without any issue. But in case of a Batch Managed child items, I get the "Cannot Add Row Without Complete Selection of Batches" error because it expects the batches to be set for the child items.

Now, what I do not understand is that how do I link the the batches of these child items with their item codes/lines. Because, the child lines/items are not fetched/set before the document is posted, it only happens AFTER you post it.

I tried setting the batches for the parent line but that does not work.

I tried manually fetching the child items (with query from ITT1) and adding new rows and set their batches, but even that doesn't work because the actual child items of the parent item are still not getting their batches set.

Also, fetching and setting child items manually just adds additional lines on top of the parent/child combination (verified by posting the draft invoice document). 

So far, the only solution I can think of is that since I can successfully post an A/R Invoice draft (which also fetches and sets the child items of the Sales BoM Item), I should just post draft, fetch it again, and then set the batches. However, that is a longer route and has a higher cost, so, I would want to avoid that. 

Has anyone encountered the above issue and successfully resolved it?

Thanks in advance
Regards

View Entire Topic
Chris1973
Active Contributor
0 Kudos

Hi @saadsabri 

The error you mentione is a classic limitation when working with Sales BoM non-inventory parent items and batch-managed child items in SAP Business One through the DI API.

Here are the reasons why you get the Error

  • When you add a Sales BoM parent item to the A/R Invoice, SAP B1 expands the BoM and creates the child lines only after the document is added.
  • Batch assignment is required at the child line level not at the parent line but those child lines do not exist in your Document.Lines collection until the system expands the BoM.
  • That is why the DI API throws: Cannot Add Row Without Complete Selection of Batches.

Here are options to Solve the error

  1. Use Draft Document → Then Assign Batches which is the approach you already tested
    • Create the invoice as a Draft with the parent item only.
    • SAP expands the BoM in the draft (child lines appear).
    • Re-load the draft, loop through Document.Lines for the child items, assign batches to the batch-managed ones.
    • Convert the draft to an A/R Invoice.
    • This is the standard safe approach because you work with the expanded structure.
  2. Use Service Layer if available
    • If you are on HANA or SQL with Service Layer, you can send the full JSON payload with parent + child + batch assignments.
    • Unlike DI API, Service Layer allows you to pass child rows explicitly with their batches in one go.
  3. Split Logic: Add Parent, Then Update Document Before Posting
    • This is technically possible but fragile:
      • Add the document with only parent rows so it creates successfully.
      • Immediately re-open it with Documents.GetByKey().
      • Assign batches to the generated child lines and update the document.
    • Drawback: You create a half-baked document and then update. There is a higher risk of posting errors.
  4. Ensure to avoid Manual Child Insertion
    • As you discovered, adding child items manually based on ITT1 only creates extra lines. SAP still expands the BoM on posting.
    • This results in duplicates and will not resolve the batch validation.

Here is my Recommendation

The officially supported and most stable method is either:

  • Draft → Assign batches → Post final invoice, or
  • Use Service Layer where you can control the full payload.

Both approaches are clean-core and avoid difficult workarounds.

SAP Business One DI API 10.0 - Objects Reference (10.00.290)

I am happy to help if you have further questions.

Best regards

Chris

saadsabri
Explorer
0 Kudos

--

saadsabri
Explorer
0 Kudos
Hi Chris. Thank you for the comprehensive solution. This is exactly what I thought and ended up doing in the end. Since I did not want to use Service Layer in this particular case, I ended up following the Draft approach. Thanks for your time.