Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Blogs / Got C/AL? / User Menu Level, Object BLO...

User Menu Level, Object BLOB – Generator code

Community Member Profile Picture Community Member Microsoft Employee

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!


This was originally posted here.

Comments

*This post is locked for comments