Follow

ITM - Mark all items with inventory movement

Important Notes

The samples and information below is provided without a warranty of any kind. This post is for informational purposes and coresystems ag assumes no responsibility for errors or omissions in the information provided.


Purpose

Sometimes in inventory counts and for inventory reports, users are only interested in items that had inventory movements. The coresuite customize rule described here creates a Function button on several reports that sets property (2) of all Items that have had inventory movements. The inventory reports can be then filtered by this item property.


Requirements

The rule requires coresuite Version 3.40 or higher, and SAP Business One 8.8 or higher.


Procedure to use this small solution

  1. Download the attached FAQ_10122_Mark_Items_w_Inventory_Movements.cocu file
  2. Import in SAP Business One via > Administration > Add-Ons > coresuite customize > Import / Export > Import rules. In the message box, select “All Active”. Click on “Import”.

To check the rule in action:

  1. Go to > Inventory > Inventory Reports 
    • Item List
    • Inactive Items
    • Inventory Posting List
    • Inventory Status
    • Inventory in Warehouse Report
    • Inventory Audit Report
    • Inventory Valuation Simulation
    • Serial Number Transaction Report
    • Batch Number Transaction Report
  2. Click on the Function button or Right Click on the form to trigger the update of all relevant items and choose "Mark Items with inventory movements".
  3. You can now filter your report by clicking on the button "Item Properties".


Procedure to adjust this small solution

The rule will update the Property 2 of the Item Master Data. In case this property is already used for something else you can adjust the code to use a different property.

The code of this rule can be used as a sample on how to update data in SAP Business One via XML instead of only DI API. This is helpful when a lot of data needs to be updated where the standard DI API update can lead to Exceptions and Time Outs.

Preview Sample (Optimizer Rule C#):

try
{
// Get only the relevant items to update via SQL Query
sql = "SELECT DISTINCT T0.ItemCode FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode WHERE T1.QryGroup2 = 'N'";
using(System.Data.SqlClient.SqlDataReader sdr = SwissAddonFramework.B1Connector.GetB1Connector().ExecuteQuery(sql))
{
while(sdr.Read())
{
// reset the error code
err = 0;
// read the item code from the query
itemCode = sdr["ItemCode"].ToString();
//StatusBar.WriteWarning("DEBUG - itemCode: " + itemCode);
// Get company and Item Object
SAPbobsCOM.Company oCompany = SwissAddonFramework.B1Connector.GetB1Connector().Company;
SAPbobsCOM.Items oItem = (SAPbobsCOM.Items) oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
oItem.GetByKey(itemCode);

/* We added 2 options to update the item only one of the options can be used */
/* BEGIN OPTION 1 - DI API - EASIER TO CODE */
//oItem.set_Properties(2, SAPbobsCOM.BoYesNoEnum.tYES);
/* END OPTION 1 - DI API */

/* BEGIN OPTION 2 - XML - BETTER PERFORMANCE */
/* // Test schema - If you are not certain which properties to update use this code to store the XML Schema
string xmlSchema = oCompany.GetBusinessObjectXmlSchema(SAPbobsCOM.BoObjectTypes.oItems);
System.IO.StreamWriter sw = new System.IO.StreamWriter("C:\\xmlForm.xml");
sw.Write(xmlSchema);
sw.Close();
*/
// Create a correct XML with the relevant nodes to get the item and update properties
tmpItem = @"<?xml version=""1.0"" encoding=""UTF-16""?><BOM><BO><AdmInfo><Object>4</Object><Version>2</Version></AdmInfo><Items><row><ItemCode>[@@ItemCode]</ItemCode><Properties2>[@@Properties2]</Properties2></row></Items></BO></BOM>";
//StatusBar.WriteWarning("DEBUG - tmpItem: " + tmpItem);
tmpItem = tmpItem.Replace("[@@ItemCode]", itemCode.Trim());
//StatusBar.WriteWarning("DEBUG - tmpItem: " + tmpItem);
tmpItem = tmpItem.Replace("[@@Properties2]", "Y");
//StatusBar.WriteWarning("DEBUG - tmpItem: " + tmpItem);
// Set the correct XML Export Type
oCompany.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_NodesAsProperties;
// Read the xml in the item
oItem.Browser.ReadXml(tmpItem, 0);
/* END OPTION 2 - XML */

err = oItem.Update();
// Check for errors and provide status
if (err == 0)
StatusBar.WriteSucess(successUpdate + itemCode);
else
{
StatusBar.WriteError(errorUpdate + itemCode + ": " + Convert.ToString(oCompany.GetLastErrorCode()) + "-" + oCompany.GetLastErrorDescription());
}
// Clean Up
oItem = null;
oCompany = null;
}
}
MessageBox.Show(finished, ok);
}
catch(System.Exception ex)
{
MessageBox.Show(errorMessage + ": \n" + ex.Message, ok);
StatusBar.WriteError(errorMessage + ": " + ex.Message);
Debug.WriteMessage(errorMessage + ": " + ex.Message, Debug.DebugLevel.Exception);
}
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.