on ‎2021 Nov 19 6:20 PM
I have the following code in an SAP add-on trying to delete a row selected in my form (where the user can choose to Add/Edit/Delete sales order lines. oMatrix is the sales order matrix and rowIndex is accurate.
// Select a cell in that row (Don't use column "0", it doesn't work. Column "1" is ItemCode)
oMatrix.Columns.Item("1").Cells.Item(rowIndex).Click(SAPbouiCOM.BoCellClickType.ct_Regular);
// return;
mainForm.SBO_Application.ActivateMenuItem("1293"); // "Click" DeleteRow
this.Close();I've seen this exact code from several people where it apparently works. My problem is the ActivateMenuItem("1293") always gives the error "Menu - Cannot activate a disabled menu item [66000-75]". It seemed the problem is that SAP hasn't been given focus back (my form has it). In fact, if I put a return after the line that "clicks" cell 1 and then manually click on the Data menu option of the Sales Order I see that Add Row, Delete Row, etc. are grayed out even though the ItemCode cell I "clicked" in is highlighted as expected. So I tried closing my form
before programmatically clicking the row (code below). Lo and behold, this time if I put a return before the ActivateMenuItem and manually click on Data menu, the Add Row, Delete Row
are active. Yay, but there's no change when I run the code without the return. Still get the error "Menu - Cannot activate a disabled menu item [66000-75]" on the ActivateMenuItem line.
this.Close();
// Select a cell in that row (Don't use column "0", it doesn't work. Column "1" is ItemCode)
oMatrix.Columns.Item("1").Cells.Item(rowIndex).Click(SAPbouiCOM.BoCellClickType.ct_Regular);
// return;
mainForm.SBO_Application.ActivateMenuItem("1293"); // "Click" DeleteRowI tried putting a delay where the //return is, no effect. I don't understand why this isn't working. The "clicking" in the ItemCode of the row should make SAP and that menu active. Please help!
Request clarification before answering.
Thank you for your answer David. Sorry for the delayed response. I was on vacation then had a lot of catch up. Anyway with regards to your answer, I am already outside of a "Lost Focus" or any other SAP event. I am clicking a button in a form I created to trigger the Delete Row action. My concern about focus is that the SAP B1 app does not have focus, my form does when I'm attempting the Delete Row. I figured that by "clicking" in a row in the SAP application it would give the focus back to SAP but it does not. Or maybe it's something else causing the error. BTW, I tried your exact code in my button press function with the same results.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Putnam,
In a similar recent case with a User Interface (UI API) program which performs the following:
and the following error is returned: Menu - Cannot activate a disabled menu item [66000-75], as per the information from our Development:
we should avoid to mimic "Click to select grid line/cell and then activate menu to delete row" via UI API in the handler of a "Lost Focus/Tab to move focus" event; in this way the "Click" won't work as expected to set menu status correctly before returning from the event handler and consequently, attempts to "Activate" menu "Delete Row" to delete the chosen row will fail. Actually, the result is, the line cannot be chosen by "Click", and focus will be moved to next item "Start Date" from "Order Date", then attempts to "Activate" disabled menu item "Delete Row" will result in exceptions.
The user can work around this issue simply by moving the "Choose and Delete" logic outside the handler of "Lost Focus" event (see below code), for example, in some manually triggered actions but not in processing of such event handlers which may affect the menu status (enablement/disablement).
private void button_ActivateMenu_Click(object sender, EventArgs e)
{
try
{
SAPbouiCOM.Form oForm = application.Forms.ActiveForm;
if(null != oForm && oForm.TypeEx == "65211")
{
SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix)oForm.Items.Item("37").Specific;
if(null != oMatrix)
{
//Click on first tab
oForm.Items.Item("35").Click();
oForm.Freeze(true);
int rowCount = oMatrix.VisualRowCount; //BG
int cellCount = oMatrix.Columns.Item("4").Cells.Count;
oMatrix.Columns.Item("4").Cells.Item(17).Click();
application.Menus.Item("1293").Activate();
// positioning on ItemCode cell
oMatrix.Columns.Item("4").Cells.Item(1).Specific.Active = true;
oForm.Freeze(false);
}
}
}
catch (Exception ex)
{
throw;
}
}Hope this helps.
Kind regards,
David Andrusko
SAP Business One Support
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 40 | |
| 21 | |
| 15 | |
| 6 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.