cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Goods Receipt via DI API sometimes fails -- what am I doing wrong?

Former Member
0 Kudos

My item master contains a couple of items for which I cannot reliably add a Goods Receipt via DI API in SAP Business One 9.0 PL9. The resulting error message is cryptic and doesn't seem applicable. I think there must be some nuance of creating a Goods Receipt that I don't understand. Here is code showing all the steps I take. What am I missing?

    public void AddGoodsReceipt(
      SAPbobsCOM.Company company,
      string receivedItemCode,
      string warehouseCode,
      double standardCost,
      double receivedQuantity,
      string referenceDoc
    ) {
      var grh = company.GetBusinessObject( SAPbobsCOM.BoObjectTypes.oInventoryGenEntry ) as SAPbobsCOM.Documents;

      grh.DocDate = DateTime.Today;
      grh.Reference1 = referenceDoc;
      grh.JournalMemo = "GR:" + referenceDoc;
      grh.Comments = "Goods Receipt: " + referenceDoc;

      var grl = grh.Lines;

      grl.ItemCode = receivedItemCode;
      grl.UnitPrice = standardCost;
      grl.Quantity = receivedQuantity;
      grl.WarehouseCode = warehouseCode;

      grl.Add();

      if ( grh.Add() != 0 ) {
        // Here we fail.
        // The error code is: -5011
        // The error message is: [IGN1.WhsCode][line:1], 'Invalid Account Code'
        // The receivedItemCode refers to an item whose GLMethod is "Item Group" (not Warehouse)
        // The same group is used for other item-group-managed items for which this code works!
        // In other words, there doesn't seem to be a difference in the configuration of items
        // which do work versus items which don't. So it makes me think some step is missing
        // in the code above.
      }
    }

Accepted Solutions (0)

Answers (8)

Answers (8)

pedro_magueija
Active Contributor

Hi Charles,

Have you checked the GL Accounts settings?

Here is a similar problem: https://archive.sap.com/discussions/thread/3617365 but with Inventory Transfer.

I'm not an accountant but here are my settings on a demo database:

Good luck.

former_member185682
Active Contributor
0 Kudos

Hi Charles,

Try check this link:

https://archive.sap.com/discussions/thread/3187695

Maybe it's your problem.

Kind Regards,

Diego Lother

Former Member
0 Kudos

Here is a failure after attempting to add with a quantity of 2. I'm still in Add mode because the add failed.

Then I changed the Remarks and changed the quantity to 1 and the add succeeded.

Former Member
0 Kudos

I just tried in the Business One Client and get the same result. I can successfully add a Goods Receipt for a quantity of 1. But if I try to add one for a quantity of 2, the add fails and the little red bar at the bottom of the screen displays the same error I reported above, but slightly more verbosely: [Goods Receipt - Rows - Warehouse Code][line: 1] , 'Invalid Account Code' [Message 173-9]

former_member185682
Active Contributor
0 Kudos

Hi Charles,

Could you share your SAP B1 goods receipt screen?

Kind Regards,

Diego Lother

Former Member
0 Kudos

The problem seems to be related to quantity. If I have a quantity of 1, the Goods Receipt will be created. A quantity of 2 or more fails. This sounds crazy, but I've reproduced it several times this afternoon. For quantity to affect a Goods Issue would make sense, because you may not be able to issue more than the quantity in inventory. But how could quantity possibly affect a Goods Receipt?

former_member185682
Active Contributor
0 Kudos

Hi Charles,

Did you try reproduce this situation in SAP B1 client?

Because SAP loads automatically account code for the line of your goods receipt, but if the account code is not defined, I believe that you need provide this information. Try too in this case set an account code in the property AccountCode in the line of your object.

Hope it helps.

Kind Regards,

Diego Lother

former_member185682
Active Contributor
0 Kudos

Hi Charles,

I can't edit the my answer :(, but desconsiders my first question about reproduce the situation in client. I didn't realize that you mentioned in your last comment.

Kind Regards,

Diego Lother

former_member233854
Active Contributor
0 Kudos

Hi,

Double check the account definition type in your item master data, depends on how it is configured you can check if the account is filled

former_member185682
Active Contributor
0 Kudos

Hi Charles,

Try do this operation by the client, and check if you reproduce this scenario in client, the SAP B1 will fill automatically the account code for the line. I believe that this item group doesn't have an "Inventory Offset - Increase" account defined.

Hope it helps.

Kind Regards,

Diego Lother

Former Member
0 Kudos

Thank you, Diego. In fact my item group does have both Inventory Offset accounts defined, so this isn't the problem. I should have mentioned in my original post that I can indeed create Goods Receipts for these items in the client. That's what leads me to believe the issue is a problem in my code rather than a configuration error in SAP.