<?xml version="1.0" encoding="utf-16"?><customize><COR_CUSTOM_FUNCB U_Active="Y" U_Description="STO_10122: Mark items with inventory movements" U_FunctionName="Mark items with inventory movements" U_Type="20" U_FormType="600,91,550,689,772,60040,900,22,46" U_NoButton="N" U_Position="0" U_ErrorBox=" " U_ErrorStatus=" " U_Creator="1" U_LastModified="18.05.2012 16:06:42" U_LastModifiedBy="1" U_Permission=""><U_Function>/****** General Information *****Creator: coresystems ag, muf@coresystems.chCreate Date: 201-05-16 ***** StartConfDesc ***** Create a function button to set the item property (2) of all Items that have had inventory movements. This helps users to count all items that had inventory movements in inventory counts.The inventory counting list can be then filtered by this item property.***** EndConfDesc ***** ***** Updates *****2012-05-16, muf: Initial Rule*/string ruleName = pVal.RuleInfo.RuleName.ToString();string errorMessage = "Error in Function Button '" + ruleName + "'";/* Translation Parameters */string successUpdate = "Successfully updated item ";string errorUpdate = "Could not update item ";string finished = "Update process to mark Items with Inventory Movements with Property 2 completed.";string ok = "OK";/* Internal Parameters */string sql = "";string itemCode = "";string tmpItem = "";int err = 0;try{	//StatusBar.WriteWarning("DEBUG - Rule: " + ruleName + " was triggered.");	// Your Code	// 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 = @"&lt;?xml version=""1.0"" encoding=""UTF-16""?&gt;&lt;BOM&gt;&lt;BO&gt;&lt;AdmInfo&gt;&lt;Object&gt;4&lt;/Object&gt;&lt;Version&gt;2&lt;/Version&gt;&lt;/AdmInfo&gt;&lt;Items&gt;&lt;row&gt;&lt;ItemCode&gt;[@@ItemCode]&lt;/ItemCode&gt;&lt;Properties2&gt;[@@Properties2]&lt;/Properties2&gt;&lt;/row&gt;&lt;/Items&gt;&lt;/BO&gt;&lt;/BOM&gt;";			//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);}</U_Function><U_PicturePath /></COR_CUSTOM_FUNCB></customize>