Hi
I have below code but menu class is not getting called.
C#
namespace Sap_B1
{
static class Program
{
public static SAPbouiCOM.Application oApplication = null;
public static SAPbobsCOM.Company oCompany = null;
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
try
{
CreateConnection();
Menu oMenuItems = null;
oMenuItems = new Menu();
// Start Message Loop
System.Windows.Forms.Application.Run();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
}
-----------------------------------------------------------------------------------------
namespace Sap_B1
{
class Menu
{
public void AddMenuItems()
{
SAPbouiCOM.Menus oMenus = null;
SAPbouiCOM.MenuItem oMenuItem = null;
oMenus = Program.oApplication.Menus;
SAPbouiCOM.MenuCreationParams oCreationPackage = null;
oCreationPackage = ((SAPbouiCOM.MenuCreationParams)(Program.oApplication.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)));
oMenuItem = Program.oApplication.Menus.Item("43520"); // moudles'
string sPath;
//sPath = Application.StartupPath;
//sPath = sPath.Remove(sPath.Length - 3, 3);
oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_POPUP;
oCreationPackage.UniqueID = "MyMenu";
oCreationPackage.String = "Salary Module";
oCreationPackage.Enabled = true;
//oCreationPackage.Image = sPath & "UI.bmp";
oCreationPackage.Position = 15;
oMenus = oMenuItem.SubMenus;
}
}
}Thanks

Amit MohantyRank #112 · 20K reputationPosted Apr 19, 2024, 7:19 AM EDT
You've defined the AddMenuItems method in the Menu class, but it's not being called anywhere in your Main method. You need to call the AddMenuItems method after instantiating the Menu class.
static void Main(string[] args) { try { CreateConnection(); Menu oMenuItems = new Menu(); oMenuItems.AddMenuItems(); // Call AddMenuItems method // Start Message Loop System.Windows.Forms.Application.Run(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }