DOC - Search Item in document rows

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.


Attached is one customize optimizer rule which create a new Label, Text box and Search button on all marketing document forms to search through the document rows for the value entered. Once a row with the entered item is found the focus goes to that row.

This is useful when a user creates documents with many rows and has to adjust one row with a certain item, for example when the quantity falls below zero.


The sample requires coresuite Version 3.50 or higher, and SAP Business One 8.8 or higher.

Procedure to use this small solution

  1. Download the attached file FAQ_10162_Search_Item_in_document_rows.cocu
  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. Open any new Sales or Purchasing Document, for example Sales Order.
  2. Enter Business Partner and several rows with items
  3. Copy one of the item codes in a lower row and paste it in the new text box created under the document currency.
  4. Select the Search button and see that the focus goes on the row with the item entered.

Procedure to adjust this small solution

You could adjust the position of the new items on the form by using a different reference element than the document currency. Also it is possible to search for a different column and value in the rows for example project or quantity.

Preview Sample (Optimizer Rule C#):

string ruleName = pVal.RuleInfo.RuleName.ToString();
string errorMessage = "Error in Optimizer Rule '" + ruleName + "'";
// Matrix and column to search
string matrixUID = "38";
// Here Item
string colUID = "1";
// Define the reference item where to position the new lable, textbox and search button
// Here the currency on the Marketing document form header
string refUID = "15";
string lableValue = "Item No.: ";
string buttonValue = "Search";
string nameSpace = "COR_";
string msgError = "Cannot search in documents rows of type Service. Change to Item Type.";
// Use a reference item to set the size and position of the new items
Item refItem = Item.GetFromUID(pVal.Form, refUID);
// Lable
Label l = Label.CreateNew(nameSpace + "L1");
l.Top = l.Top + 40;
l.Value = lableValue;
// Text box to enter value to search for
TextEdit t = TextEdit.CreateNew(nameSpace + "T1");
t.Left = l.Left + l.Width + 15;
// Search Button
Button b = Button.CreateNew(nameSpace + "B1");
b.Value = buttonValue;
b.Left = t.Left + t.Width + 15;
// Add the new items ...
// ...and update the form
// Now add a delegate to react when the user selects the search button
SwissAddonFramework.UI.EventHandling.ItemEvents.ItemPressedEventHandler ev = null;
ev = delegate (SwissAddonFramework.UI.EventHandling.ItemEvents.ItemPressed e)
// Check the document type since the search only works for items
string docType = ComboBox.GetFromUID(pVal.Form, "3").Value;
if (docType == "S")
// If the Document is of Item Type get the matrix...
Matrix m = Matrix.GetFromUID(pVal.Form, matrixUID);
// ... and search in the rows
for (int index = 0; index < m.Rows.Count; index++)
string mItem = m.GetValue(colUID, index);
if (mItem == t.Value)
// find the first row with the item entered
m.Columns["0"].Cells[index].Click(SwissAddonFramework.UI.Components.MatrixColumn.ClickTypes.Regular, SwissAddonFramework.UI.Components.MatrixColumn.Modifier.None);
catch (Exception ex)
StatusBar.WriteError(errorMessage + ": " + ex.Message);

b.AddHandler_ItemPressed(SwissAddonFramework.UI.Components.ModeComponent.FormModes.ALL, null, ev);
catch(System.Exception ex)
//MessageBox.Show(errorMessage + ": \n" + ex.Message, "OK");
StatusBar.WriteError(errorMessage + ": " + ex.Message);
Debug.WriteMessage(errorMessage + ": " + ex.Message, Debug.DebugLevel.Exception);
return true;
Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request



Please sign in to leave a comment.