Skip to Content
Author's profile photo DIEGO LOTHER

Getting a list of Menu UIDs in Sap B1

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:

Application.PNG

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.

Assigned Tags

      15 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      very good, thank you for sharing.

      i usually save the list as xml using the following method:

      String menuList = Application.SBO_Application.Menus.GetAsXML();

      Author's profile photo DIEGO LOTHER
      DIEGO LOTHER
      Blog Post Author

      Hi christian,

      I'm glad for you like it, thanks for your comment and your sharing your own solution.

      Regards,

      Diego

      Author's profile photo Former Member
      Former Member

      very good, thank you for sharing

      Author's profile photo DIEGO LOTHER
      DIEGO LOTHER
      Blog Post Author

      Thanks Diego.

      Author's profile photo Lan Zhang
      Lan Zhang

      Hi DIEGO,

      This is exactly what I am looking for now. 🙂

      Thank you for your code sharing!

      Lan 

      Author's profile photo Mahendrakumar D.P.
      Mahendrakumar D.P.

      Hello Dirgo,

      Can I get Menu ID of User Defined No Object Type table ?

       

      Thanks,

      Mahendra

      Author's profile photo DIEGO LOTHER
      DIEGO LOTHER
      Blog Post Author

      Hi Mahendrakumar,

      You want to say the forms that you see under the Tools -> User-Defined Windows?

      If yes, just enable the option system information under the view menu and hover your mouse over the menu option that you want to know the menu uid. But remember User-Defined Windows have diferents menu uids in diferent companies.

      Hope it helps,

      Kind Regards,

      Diego Lother

      Author's profile photo Mahendrakumar D.P.
      Mahendrakumar D.P.

      I want to access Menus under User-Defined Windows though SDK? is it possible?

      Author's profile photo DIEGO LOTHER
      DIEGO LOTHER
      Blog Post Author

      Hi Mahendrakumar,

      Yes, it's possible.

      Use the following code:

      SBO_Application.ActivateMenuItem("51274");

      SBO_Application is your application object. Where you see "51274", replaces with the menu id of your user defined window.

      Hope it helps.

      Kind Regards,

      Diego Lother

      Author's profile photo Mahendrakumar D.P.
      Mahendrakumar D.P.

       

      Hello Diego,

      I know this. But I don’t know which menu UID will be assigned to my User Defined table with No Object Type. After Creating UDO that Menu UID Assigned by System.

      Is there any entry in table where I can find 51202 Menu UID is Assigned to UDO “Test”.

       

      Thanks

      Mahendrakumar

       

      Author's profile photo DIEGO LOTHER
      DIEGO LOTHER
      Blog Post Author

      Hi Mahendrakumar,

      This menu uid is dynamic and can change if a new user defined table is added. But to get the menu uid of your not object user defined table you can use this sql:

      SELECT 
      	MenuUid
      FROM
      	(SELECT (RANK() OVER (ORDER BY TableName)) + 51200 AS MenuUid, TableName, Descr FROM OUTB WHERE ObjectType = 0) T0
      WHERE
      	TableName = 'your user table name'

      I believe this solve your problem.

      Hope it helps.

      Kind Regards,

      Diego Lother

       

      Author's profile photo Mahendrakumar D.P.
      Mahendrakumar D.P.

       

      Hello Diego,

      I want to know how to give you points for your use full answer? Do let me know?

      Thanks,

      Mahendrakumar

      Author's profile photo DIEGO LOTHER
      DIEGO LOTHER
      Blog Post Author

      Hi Mahendrakumar,

      It's not possible do something like this in blog post. In blog post you only are able to like the blog post and like the comments, but no problem I'm glad to help.

      Kind Regards,

      Diego Lother

      Author's profile photo Mahendrakumar D.P.
      Mahendrakumar D.P.

      Thanks a lot Diego !!!

       

       

      Author's profile photo Andres Garrido
      Andres Garrido

      Hi, where is the document?