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
Attached is 1 customize optimizer rule that will adjust the standard choose from list when selecting items in rows of documents. So you can display additional columns with more detailed item information in the choose from list.
Requirements
The sample requires coresuite Version 3.50 or higher, and SAP Business One 8.8 or higher.
Procedure to use this small solution
- Download the attached file FAQ_10182_CustomCFL.cocu
- 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”.
- Open any new Sales Order.
- Enter Business Partner
- Open the choose from list in the rows to select an item
- See that a different choose from list that the standard opens
Procedure to adjust this small solution
This rule can be used by those users who want to personalize the displayed Choose From List (CFL) when the standard SAP Business One CFL does not provide enough information. In the code below and in attached rule the changes to be done for different cases are highlighted with TODO and described.
In total only 3 lines of code need to be changed in 80% of the use cases.
Preview Sample (Optimizer Rule C#):
/* Parameters to adjust */
string formDescription = "Item Selection";
// TODO: write here the main query that should be executed without filtering
string query = "SELECT ItemCode, ItemName FROM OITM";
if (pVal.Item is Matrix)
{
string val = ((Matrix) pVal.Item).GetValue(pVal.ColUID, pVal.Row - 1);
if (!String.IsNullOrEmpty(val))
return true;
}
else if (pVal.Item is TextEdit)
{
string val = ((TextEdit) pVal.Item).Value;
if (!String.IsNullOrEmpty(val))
return true;
}
string salt = SwissAddonFramework.Utils.UniqueStringGenerator.Next();
Form f = Form.CreateNewForm("F1", "F1_" + salt);
f.Value = formDescription;
f.Top = pVal.Form.Top + 50;
f.Left = pVal.Form.Left + 50;
f.DefButton = "1";
TextEdit txtFind = TextEdit.CreateNew("T1");
txtFind.SetPosition(10, 10);
txtFind.Width = 100;
Grid g = Grid.CreateNew("G1");
g.SetSizeAndPosition(10, 50, f.Width - 50, f.Height - 100);
g.SelectionMode = SwissAddonFramework.UI.Components.Grid.SelectionModes.Auto;
g.Enabled = false;
Button bOK = Button.CreateNew("1");
bOK.SetPosition(10, g.Top + g.Height + 5);
Button bCancel = Button.CreateNew("2");
bCancel.SetPosition(bOK.Left + bOK.Width + 10, bOK.Top);
f.AddItem(txtFind);
f.AddItem(g);
f.AddItem(bOK);
f.AddItem(bCancel);
f.Load();
g.ExecuteQuery(query);
SwissAddonFramework.UI.EventHandling.ItemEvents.KeyDownEventHandler delKeyDown = null;
delKeyDown = delegate (SwissAddonFramework.UI.EventHandling.ItemEvents.KeyDown ev2)
{
f.Freeze(true);
string tmp = null;
try {
// TODO: here you can apply a filter when the user starts typing on the search field
tmp = query + " WHERE ItemCode LIKE '%" + txtFind.Value + "%'";
// at this stage the query would look like:
// SELECT ItemCode, ItemName FROM OITM WHERE ItemCode LIKE '%mySearch%'
g.ExecuteQuery(tmp);
}
catch (Exception ex2)
{
StatusBar.WriteError(errorMessage + " - Query error: " + tmp);
Debug.WriteMessage(errorMessage + " - Query error: " + tmp, Debug.DebugLevel.Exception);
}
f.Freeze(false);
};
txtFind.AddHandler_KeyDown(SwissAddonFramework.UI.Components.ModeComponent.FormModes.ALL, null, delKeyDown);
SwissAddonFramework.UI.EventHandling.ItemEvents.ItemPressedEventHandler delItemPressed = null;
delItemPressed = delegate (SwissAddonFramework.UI.EventHandling.ItemEvents.ItemPressed ev)
{
try
{
string[] itemCodeList = new string[g.SelectedRows.Count];
for (int index = 0; index < g.SelectedRows.Count; index++)
{
// TODO: here write the column that should be written back to the item where the action has been triggered.
itemCodeList[index] = g.GetValue("ItemCode", g.SelectedRows.RowIndex(index));
// In this case the column "ItemCode".
// This MUST match one of the columns returned by the query.
}
f.Close();
if (pVal.Item is Matrix)
{
Matrix m = (Matrix) pVal.Item;
for (int index = 0; index < itemCodeList.Length; index++)
{
m.SetValue(pVal.ColUID, pVal.Row - 1 + index, itemCodeList[index]);
}
}
else if (pVal.Item is TextEdit)
{
TextEdit tx = (TextEdit) pVal.Item;
tx.Value = itemCodeList[0];
}
}
catch (Exception ex)
{
StatusBar.WriteError(errorMessage + ": " + ex.Message);
Debug.WriteMessage(errorMessage + ": " + ex.Message, Debug.DebugLevel.Exception);
}
};
bOK.AddHandler_ItemPressed(SwissAddonFramework.UI.Components.ModeComponent.FormModes.ALL, delItemPressed);
Comments
0 comments
Please sign in to leave a comment.