Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member185682
Active Contributor

Every time I need to know the menu UID from SAP B1 Menu, I have to go to the “View” option menu, and enable the “system information” option, moving the mouse over it. However, sometimes I already have the UID, and what I need is the Menu Name. In this case, the SDK documentation does not mention anything about it.


Based on the Application Object from the UI API, we have the following structure:

To help anybody to find out the menu´s name, I wrote a sample code that collect each item menu and writes in a CSV file.

Code:

    static class Program

    {

        private static SAPbouiCOM.Application objApp = null;

        private static System.IO.StreamWriter file = null;

        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        [STAThread]

        static void Main()

        {

            try

            {

                SAPbouiCOM.SboGuiApi objSBOGuiApi = null;

                objSBOGuiApi = new SAPbouiCOM.SboGuiApi();

                objSBOGuiApi.Connect((string)Environment.GetCommandLineArgs().GetValue(1));

                objApp = objSBOGuiApi.GetApplication();

                objApp.MessageBox("Connected by UI API");

                file = new System.IO.StreamWriter("C:\\listMenus.csv");

                file.WriteLine("Father Menu UID;Father Menu Name;Menu UID;Menu Name");

                listMenus(objApp.Menus, string.Empty, string.Empty);

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

            finally

            {

                if (file != null)

                    file.Close();

            }

        }

        private static void listMenus(SAPbouiCOM.Menus menus, string fatherMenuName, string fatherMenuUID)

        {

            if (menus != null && menus.Count > 0)

            {

                foreach (SAPbouiCOM.MenuItem menuItem in menus)

                {

                    string line = fatherMenuUID + ";" + fatherMenuName + ";" + menuItem.UID + ";" + menuItem.String;

                    file.WriteLine(line.Replace("&", ""));

                    listMenus(menuItem.SubMenus, menuItem.String, menuItem.UID);

                }

            }

        }

    }

The file generate with this code in my SAP B1 is attached to this document.

My SAP B1 version is 9 PL 11 and the version of my SAPbouiCOM is 9.0.

I hope this document can help everyone who are starting with SAP B1 SDK.

15 Comments
Labels in this area