Skip to Content

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

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.
      }
    }

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

8 Answers

  • Oct 14, 2016 at 02:46 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 14, 2016 at 12:45 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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.

  • Oct 14, 2016 at 01:15 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

  • Oct 14, 2016 at 01:14 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 14, 2016 at 05:28 PM

    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?

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 14, 2016 at 05:51 PM

    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]

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 14, 2016 at 07:03 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 14, 2016 at 11:36 PM

    Hi Charles,

    Try check this link:

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

    Maybe it's your problem.

    Kind Regards,

    Diego Lother

    Add comment
    10|10000 characters needed characters exceeded