Oct 06

Yesterdays post on assigning MenuSuite Menu’s programatically got a lot of hits, and i have been getting a couple of emails about how to create the data for the blob field. In this post I will show how to build the BLOB generator i Dynamics NAV.

The BLOB content is reverse engineered on Mayank’s Extreme Engineering blog.

First we need to define some variables:

  • UserMenuLevel – Record User Menu Level
  • Stream – OutStream
  • Char – Char
  • MenuSuiteMenu – Record MenuSuiteMenu, custom table with 3 fields GUID, Name and Enabled (bool)

In this example we just write directly to a already existing User Menu Level. So setup the BLOB for writing:

UserMenuLevel.GET('SOREN-D530\SOREN',UserMenuLevel."ID Type"::Windows,UserMenuLevel.Level::"User Restrictions");
UserMenuLevel.Object.CREATEOUTSTREAM(Stream);

Now we can use the methods of the Stream to write to our BLOB. The BLOB needs to start with 4 bytes indicating the total size of the BLOB – 36 bytes:

// size 4 bytes
Size := (95 + (MenuSuiteMenu.COUNT * 32)) - 36;
WriteChar4(Size MOD 256,Size DIV 256,Size DIV 256*256,Size DIV 256*256*256);

The first part of the BLOB is a fixed length of 95 bytes + x * 32 bytes for each MenuSuite Menu.

Then there is another fixed section:

// fixed data
WriteChar4(8,0,0,0);
WriteChar4(1,0,0,0);
WriteChar4(12,0,0,0);
WriteChar4(100,0,0,0);
WriteChar4(1,0,0,0);
WriteChar4(1,19,0,0);
WriteChar4(7,0,0,0);
WriteChar4(1,0,0,0);
WriteChar4(44,0,0,0);
WriteChar4(12,0,0,0);
WriteChar4(1,0,0,0);
WriteChar4(20,0,0,0);
WriteChar4(100,0,0,0);
WriteChar4(0,0,0,0);
WriteChar4(1,11,4,0);
WriteChar4(0,0,0,0);
WriteChar4(2,11,7,0);
WriteChar4(0,0,0,0);
WriteChar4(0,0,0,0);

Then there is a remaining BLOB len and no. of menusuites we need to set:

// remaining size 4 bytes
WriteChar4((Size-44) MOD 256,(Size-44) DIV 256,0,0);
WriteChar4(20,0,0,0);
// no of menusuites
WriteChar4(MenuSuiteMenu.COUNT MOD 256,MenuSuiteMenu.COUNT DIV 256,MenuSuiteMenu.COUNT DIV 256*256,MenuSuiteMenu.COUNT DIV 256*256*256);

Then we write our GUIDS to the BLOB:

//guids go here
IF MenuSuiteMenu.FINDSET THEN REPEAT
WriteChar4(12,0,0,0);
// guid
Stream.WRITE(MenuSuiteMenu.GUID);
UNTIL MenuSuiteMenu.NEXT = 0;

Notice writing GUIDs to a stream directly, creates them in their right format, and finally set their permissions:

IF MenuSuiteMenu.FINDSET THEN REPEAT
WriteChar4(39,221,4,0);
IF MenuSuiteMenu.Enabled THEN
WriteChar4(0,0,0,0)
ELSE
WriteChar4(1,0,0,0);
WriteChar4(0,0,0,0);
UNTIL MenuSuiteMenu.NEXT = 0;
UserMenuLevel.MODIFY;

Oh, and you might have wondered, but the WriteChar4 is just a function for writing 4 bytes at the time:

WriteChar4(Char1 : Char;Char2 : Char;Char3 : Char;Char4 : Char)
Stream.WRITE(Char1);
Stream.WRITE(Char2);
Stream.WRITE(Char3);
Stream.WRITE(Char4);

That is it. To update your MenuSuite, you can right click in the bottom of it and select refresh. Thanks. If you have a good implementation of it, write about it here. Enjoy!

9 Responses to “User Menu Level, Object BLOB – Generator code”

  1. Mayank says:

    Amazing, you implementation is way better than mine.

  2. Alex says:

    I want to ask how to get MenuSuite Namd and GUID??
    Is it export MenuSuite Object as Text file and use dataport to import the List??

  3. Actually I used the export object functionality of 2009, as it exports it as text. And then a simple dataport to read in the GUID for the Names.

  4. Alex says:

    Sorry ~~~ i have no idea how to implement a dataport to read the text file with MenuSuite name and GUID.
    In the text file, it has other menu item and node information, how can i seprate them.

  5. Alex says:

    Really , Really thanks your post . I have prefectly to modify the Menu Suite Object .
    I have one more question. If i want to read the Menu Suite Object, is it the same way with INStream?? and readEach Char?

  6. Erik says:

    Excellent site!! even the old posts. I just openen 10 TABs with links and this is the first. Could I ask you for the code in fob format. Im not sure what the picture on right should show therefor iam asking.

  7. OsminohejTygr says:

    Thank you very much for this great article. Just one question. Is`t Size DIV 256 statment cause char overflow, when Size>=256*256?

    • krish says:

      Hi,
      it’s really old post but just wondering if you have tried to fix the overflow issue
      [Is`t Size DIV 256 statment cause char overflow, when Size>=256*256?] .

      With this code you can manage only 6 menus. Not more than that. Any idea? Thanks..

  8. ALopez says:

    I exported the menu object to text but I’m having problems matching these to the Object hex characters, is there an easy method to match users to what menus they have access to (are assigned)? Just want a simple list of users to what menus they have permissions to. THanks.

Leave a Reply to ALopez

preload preload preload
pornpants.com pornofri.com kilporn.com