Skip to Content
Product Information
Author's profile photo ANKIT CHAUHAN

Inventory Posting in SAP Business One SDK

About Inventory Posting:

Inventory Posting is used to reconcile the item quantities with the Inventory Counting results.

After creating an Inventory Counting document to record the counting results, you must post the inventory changes to effect the adjustments in the system. For this, you need to create an Inventory Posting document based on the Inventory Counting document.

To access this window, from the SAP Business One Main Menu, choose  Inventory  Inventory Transactions Inventory Counting Transactions  Inventory Posting

For more details on Inventory Posting, you can refer to following link:

https://help.sap.com/saphelp_sbo92/helpdata/en/2f/ca149512334ee58fd95c1c9b3af841/content.htm

Using Inventory Posting in SAP Business One SDK:

Inventory Posting is exposed as a service type Object (InventoryPostingsService) in SAP Business One SDK.

Add an Inventory Posting Document using DI API:

SAPbobsCOM.CompanyService oCS = (SAPbobsCOM.CompanyService)oCompany.GetCompanyService();
SAPbobsCOM.InventoryPostingsService oInventoryPostingsService = oCS.GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryPostingsService);
SAPbobsCOM.InventoryPosting oInventoryPosting = oInventoryPostingsService.GetDataInterface(SAPbobsCOM.InventoryPostingsServiceDataInterfaces.ipsInventoryPosting);
oInventoryPosting.CountDate = DateTime.Now;
SAPbobsCOM.InventoryPostingLines oInventoryPostingLines = oInventoryPosting.InventoryPostingLines;
SAPbobsCOM.InventoryPostingLine oInventoryPostingLine = oInventoryPostingLines.Add();
oInventoryPostingLine.ItemCode = "B10000";
oInventoryPostingLine.CountedQuantity = 13;
oInventoryPostingLine.WarehouseCode = "05";
oInventoryPostingLine.BinEntry = 2;
oInventoryPostingLine.Price = 58;
oInventoryPostingLine.UoMCode = "Carton";
oInventoryPostingLine.UoMCountedQuantity = 12;
SAPbobsCOM.InventoryPostingBatchNumber oInventoryPostingBatchNumber = oInventoryPostingLine.InventoryPostingBatchNumbers.Add();
oInventoryPostingBatchNumber.BatchNumber = "B-B1234";
oInventoryPostingBatchNumber.Quantity = 288;
SAPbobsCOM.InventoryPostingParams oInventoryPostingParams = oInventoryPostingsService.Add(oInventoryPosting);

Update an Inventory Posting Document using DI API:

SAPbobsCOM.CompanyService oCS = (SAPbobsCOM.CompanyService)oCompany.GetCompanyService();
SAPbobsCOM.InventoryPostingsService oInventoryPostingsService = oCS.GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryPostingsService);
SAPbobsCOM.InventoryPostingParams oInventoryPostingParams = (SAPbobsCOM.InventoryPostingParams)oInventoryPostingsService.GetDataInterface(SAPbobsCOM.InventoryPostingsServiceDataInterfaces.ipsInventoryPostingParams);
oInventoryPostingParams.DocumentEntry = 1;
SAPbobsCOM.InventoryPosting oInventoryPosting = oInventoryPostingsService.Get(oInventoryPostingParams);
oInventoryPosting.Remarks = "TEST DI API";
oInventoryPostingsService.Update(oInventoryPosting);

Assigned Tags

      15 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Andres Ramirez Jaramillo
      Andres Ramirez Jaramillo

      Hello ANKIT CHAUHAN
      How could I export and import via XML, as well as SaveXML and GetBusinessObjectFromXML?
      Thank you

      Andres Ramirez Jaramillo

      Author's profile photo ANKIT CHAUHAN
      ANKIT CHAUHAN
      Blog Post Author

      Hi Andres Ramirez Jaramillo,

      To prepare and debug an XML Payload or to detect the correctness of the XML payload, DI Tool can be used. It lists all DI objects and services supported by the currently selected DI API version. Also, it generates XML sample code for an object schema or a service schema.

      Refer to SAP Note 2057143 for the same.

      Hope it helps!

      Kind regards,

      ANKIT CHAUHAN

      SAP Business One Support

      Author's profile photo Rakesh Singh
      Rakesh Singh

      Hello Ankit,

      Could you further provide code for posting multiple lines.

      When we are posting data with multiple lines, then in SAP it is only showing one line. (only first line items is showing but the line number shows 2)

      So, any code sample with multiple line items would be helpful.

      Author's profile photo ANKIT CHAUHAN
      ANKIT CHAUHAN
      Blog Post Author

      Hi Rakesh Singh,

      Following sample should work:

      SAPbobsCOM.CompanyService oCS = (SAPbobsCOM.CompanyService)oCompany.GetCompanyService();
      SAPbobsCOM.InventoryPostingsService oInventoryPostingsService = oCS.GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryPostingsService);
      SAPbobsCOM.InventoryPosting oInventoryPosting = oInventoryPostingsService.GetDataInterface(SAPbobsCOM.InventoryPostingsServiceDataInterfaces.ipsInventoryPosting);
      oInventoryPosting.CountDate = DateTime.Now;
      SAPbobsCOM.InventoryPostingLines oInventoryPostingLines = oInventoryPosting.InventoryPostingLines;
      SAPbobsCOM.InventoryPostingLine oInventoryPostingLine = oInventoryPostingLines.Add();
      oInventoryPostingLine.ItemCode = "A00003";
      oInventoryPostingLine.CountedQuantity = 596;
      oInventoryPostingLine.WarehouseCode = "01";
      
      oInventoryPostingLine = oInventoryPostingLines.Add();
      oInventoryPostingLine.ItemCode = "A00004";
      oInventoryPostingLine.CountedQuantity = 562;
      oInventoryPostingLine.WarehouseCode = "01";

      Kind regards,

      ANKIT CHAUHAN

      SAP Business One Support

      Author's profile photo Sayali Bhogate
      Sayali Bhogate

      Hi Ankit,

      I'm getting below error. could you please review this and suggest?

      Cannot add row without complete selection of batch/serial numbers

       

      Here is the Code sample :

      SAPbobsCOM.InventoryPostingLines oInventoryPostingLines = oInventoryPosting.InventoryPostingLines;
      SAPbobsCOM.InventoryPostingLine oInventoryPostingLine = oInventoryPostingLines.Add();
      oInventoryPostingLine.ItemCode = "Test001";
      oInventoryPostingLine.CountedQuantity = 1;
      oInventoryPostingLine.WarehouseCode = "QTYIQ156";

      SAPbobsCOM.InventoryPostingBatchNumber oInventoryPostingBatchNumber = oInventoryPostingLine.InventoryPostingBatchNumbers.Add();
      oInventoryPostingBatchNumber.BatchNumber = "B2";
      oInventoryPostingBatchNumber.Quantity = Convert.ToDouble(1.0);

      Author's profile photo ANKIT CHAUHAN
      ANKIT CHAUHAN
      Blog Post Author

      Hi Sayali Bhogate,

      Check whether it is related to UoM or UoM Counted Quantity? You may need to provide more Batch Quantity if it is related to UoM or UoM Counted Quantity.

      Kind regards,

      ANKIT CHAUHAN

      SAP Business One Support

      Author's profile photo Sayali Bhogate
      Sayali Bhogate

      Hi Ankit,

      Thank You for your quick response.

      I have checked but, UoM Group is manual for Itemcode that I'm sending in DIAPI.

      But still I tried & getting below error:

      234000032 - Line 1; UoM group is manual for item code 'Test001'; UoM counted quantity not needed [IQR1.UomQty][line: 1]

       

       

      Author's profile photo ANKIT CHAUHAN
      ANKIT CHAUHAN
      Blog Post Author

      Hi Sayali Bhogate,

      In that case, I would suggest you to create an incident for SAP Business One Support team under the component SBO-SDK-DI to get it investigated.

      Kind regards,

      ANKIT CHAUHAN

      SAP Business One Support

      Author's profile photo Jithin George
      Jithin George

      Hi.

      I am also getting the error "Cannot add row without complete selection of batch/serial numbers"

      Here is the full code

       

      SAPbobsCOM.Recordset Rec;
      try
      {
      Rec = (SAPbobsCOM.Recordset)Form1.SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
      SAPbobsCOM.CompanyService oCS = (SAPbobsCOM.CompanyService)Form1.SBOCompany.GetCompanyService();

      SAPbobsCOM.InventoryPostingsService oInventoryPostingsService = (SAPbobsCOM.InventoryPostingsService)oCS.GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryPostingsService);

      SAPbobsCOM.InventoryPosting oInventoryPosting = (SAPbobsCOM.InventoryPosting)oInventoryPostingsService.GetDataInterface(SAPbobsCOM.InventoryPostingsServiceDataInterfaces.ipsInventoryPosting);

      string date = ((SAPbouiCOM.EditText)frmInvCounter.Items.Item("txtCDate").Specific).Value.ToString();
      string a = date.Substring(0, 4);
      string b = date.Substring(4, 2);
      string c = date.Substring(6, 2);
      DateTime IncCountDate = new DateTime(Convert.ToInt32(a), Convert.ToInt32(b), Convert.ToInt32(c));

      oInventoryPosting.CountDate = IncCountDate;

      oInventoryPosting.Remarks = ((SAPbouiCOM.EditText)frmInvCounter.Items.Item("txtRemarks").Specific).Value.ToString();

      //oInventoryPosting.PriceSource = SAPbobsCOM.InventoryPostingPriceSourceEnum.ippsItemCost;
      oInventoryPosting.PriceSource = SAPbobsCOM.InventoryPostingPriceSourceEnum.ippsLastEvaluatedPrice;

      SAPbobsCOM.InventoryPostingLines oInventoryPostingLines = oInventoryPosting.InventoryPostingLines;

      for (int i = 1; i <= _omtInventory.VisualRowCount ; i++)
      {
      SAPbobsCOM.InventoryPostingLine oInventoryPostingLine = oInventoryPostingLines.Add();
      oInventoryPostingLine.ItemCode = ((SAPbouiCOM.EditText)_omtInventory.Columns.Item("CItemCode").Cells.Item(i).Specific).Value;
      oInventoryPostingLine.ItemDescription = ((SAPbouiCOM.EditText)_omtInventory.Columns.Item("CItemDesc").Cells.Item(i).Specific).Value;
      oInventoryPostingLine.WarehouseCode = ((SAPbouiCOM.EditText)_omtInventory.Columns.Item("CWhse").Cells.Item(i).Specific).Value;

      Rec.DoQuery("select AbsEntry from OBIN where BinCode='" + ((SAPbouiCOM.EditText)_omtInventory.Columns.Item("CBinLctn").Cells.Item(i).Specific).Value + "'");
      int _BinEntry = Convert.ToInt32(Rec.Fields.Item("AbsEntry").Value.ToString());
      oInventoryPostingLine.BinEntry = _BinEntry;

      SAPbobsCOM.InventoryPostingBatchNumber oInventoryPostingBatchNumber = oInventoryPostingLine.InventoryPostingBatchNumbers.Add();
      oInventoryPostingBatchNumber.BatchNumber = ((SAPbouiCOM.EditText)_omtInventory.Columns.Item("CBatchNo").Cells.Item(i).Specific).Value;
      oInventoryPostingBatchNumber.ManufacturerSerialNumber = ((SAPbouiCOM.EditText)_omtInventory.Columns.Item("CBatchAtt").Cells.Item(i).Specific).Value;
      oInventoryPostingBatchNumber.Quantity = Convert.ToDouble(((SAPbouiCOM.EditText)_omtInventory.Columns.Item("CINWhsQty").Cells.Item(i).Specific).Value);

      oInventoryPostingLine.CountedQuantity = Convert.ToDouble(((SAPbouiCOM.EditText)_omtInventory.Columns.Item("CCountQty").Cells.Item(i).Specific).Value);
      oInventoryPostingLine.Variance = Convert.ToDouble(((SAPbouiCOM.EditText)_omtInventory.Columns.Item("CVariance").Cells.Item(i).Specific).Value);
      //oInventoryPostingLine.InWarehouseQuantity= Convert.ToDouble(((SAPbouiCOM.EditText)_omtInventory.Columns.Item("CINWhsQty").Cells.Item(i).Specific).Value);
      }
      SAPbobsCOM.InventoryPostingParams oInventoryPostingParams = oInventoryPostingsService.Add(oInventoryPosting);

      Author's profile photo ANKIT CHAUHAN
      ANKIT CHAUHAN
      Blog Post Author

      Hi Jithin George,

      I would suggest you to create an incident for SAP Business One Support team under the component SBO-SDK-DI to get it investigated.

      Kind regards,

      ANKIT CHAUHAN

      SAP Business One Support

      Author's profile photo Rafael Barquero
      Rafael Barquero

      Hi Ankit

       

      There is any way to use an InventoryCounting as source for the InventoryPosting?? something like CopyFrom using SDK?

       

      I sucessfully created an InventoryCounting document using SDK but I want to complete the cycle adding the Posting for that counting.

       

      Can you share some code if possible?

      Author's profile photo ANKIT CHAUHAN
      ANKIT CHAUHAN
      Blog Post Author

      Dear Rafael Barquero,

      My question to you, can the same operation/functionality be performed manually using SAP Business One client?

      If yes, please share the steps how it works and I can give it a try.

      If no, the same cannot be achieved via SAP Business One SDK.

      Kind regards,

      ANKIT CHAUHAN

      SAP Business One Support

      Author's profile photo Rafael Barquero
      Rafael Barquero

      Sure, this process is the regular process for Inventory Counting.

      You create a Inventory Count document at Inventory Module>Inventory Transactions>Inventory Counting Transactions>Inventory Counting. This document is used to catch phisical stock at warehouse. The system will compare that count with the calculated quantity and define any difference plus or minus.

      When the couting process is done, the user click the button "Copy to Inventory Posting" and this will create a new Inventory Posting transaction for the adjusment calculated, when this new document is created, the system made the adjustment to item's quantities and the process is closed. Both documents are linked as source and Tarjet one to the other.

      At this point I'm able to create both documents separated but I couldn't find the way to link the Counting with the Posting as the "Copy to Inventory Posting" button does.

      I hope this is the information you asked for.

      Author's profile photo ANKIT CHAUHAN
      ANKIT CHAUHAN
      Blog Post Author

      Dear Rafael Barquero,

      Use the following sample code to create Inventory Posting based on Inventory Counting using DI API:

      try
      {
          var InventoryPostingService = (SAPbobsCOM.InventoryPostingsService)oCompany.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.InventoryPostingsService);
          var oInventoryPosting = (SAPbobsCOM.InventoryPosting)InventoryPostingService.GetDataInterface(SAPbobsCOM.InventoryPostingsServiceDataInterfaces.ipsInventoryPosting);
          var line = oInventoryPosting.InventoryPostingLines.Add();
          line.BaseEntry = 3;
          line.BaseLine = 1;
          line.BaseType = 1470000065;
          InventoryPostingService.Add(oInventoryPosting);
          oInventoryPosting.ToXMLFile("./AddInventoryPosting.xml");
      }
      
      catch (Exception ex)
      {
          MessageBox.Show(ex.Message);
      }

      Kind regards,

      ANKIT CHAUHAN

      SAP Business One Support

      Author's profile photo Rafael Barquero
      Rafael Barquero

      Ok, you are only setting the baseline link.

      I suppouse I should close Inventory Count as well to complete the link simulation.

      Thanks  Ankit.