Product Information
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 →
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);
Hello ANKIT CHAUHAN
How could I export and import via XML, as well as SaveXML and GetBusinessObjectFromXML?
Thank you
Andres Ramirez Jaramillo
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
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.
Hi Rakesh Singh,
Following sample should work:
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
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);
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
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]
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
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);
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
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?
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
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.
Dear Rafael Barquero,
Use the following sample code to create Inventory Posting based on Inventory Counting using DI API:
Kind regards,
ANKIT CHAUHAN
SAP Business One Support
Ok, you are only setting the baseline link.
I suppouse I should close Inventory Count as well to complete the link simulation.
Thanks Ankit.