{"id":671,"date":"2010-10-06T00:48:50","date_gmt":"2010-10-06T07:48:50","guid":{"rendered":"http:\/\/45.63.48.66\/?p=671"},"modified":"2019-05-02T14:56:54","modified_gmt":"2019-05-02T21:56:54","slug":"user-menu-level-object-blob-generator-code","status":"publish","type":"post","link":"https:\/\/gotcal.com\/index.php\/2010\/10\/user-menu-level-object-blob-generator-code\/","title":{"rendered":"User Menu Level, Object BLOB \u2013 Generator code"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-680\" title=\"binary\" src=\"\/wp-content\/uploads\/2010\/10\/binary-150x150.jpg\" alt=\"\" width=\"198\" height=\"255\">Yesterdays post on assigning MenuSuite Menu&#8217;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.<\/p>\n<p>The BLOB content is reverse engineered on Mayank&#8217;s Extreme Engineering blog.<\/p>\n<p><!--more-->First we need to define some variables:<\/p>\n<ul>\n<li>UserMenuLevel &#8211; Record User Menu Level<\/li>\n<li>Stream &#8211; OutStream<\/li>\n<li>Char &#8211; Char<\/li>\n<li>MenuSuiteMenu &#8211; Record MenuSuiteMenu, custom table with 3 fields GUID, Name and Enabled (bool)<\/li>\n<\/ul>\n<p>In this example we just write directly to a already existing User Menu Level. So setup the BLOB for writing:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nUserMenuLevel.GET('SOREN-D530\\SOREN',UserMenuLevel.&quot;ID Type&quot;::Windows,UserMenuLevel.Level::&quot;User Restrictions&quot;);\nUserMenuLevel.Object.CREATEOUTSTREAM(Stream);<\/pre>\n<p>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 &#8211; 36 bytes:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ size 4 bytes\nSize := (95 + (MenuSuiteMenu.COUNT * 32)) - 36;\nWriteChar4(Size MOD 256,Size DIV 256,Size DIV 256*256,Size DIV 256*256*256);<\/pre>\n<p>The first part of the BLOB is a fixed length of 95 bytes + x * 32 bytes for each MenuSuite Menu.<\/p>\n<p>Then there is another fixed section:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ fixed data\nWriteChar4(8,0,0,0);\nWriteChar4(1,0,0,0);\nWriteChar4(12,0,0,0);\nWriteChar4(100,0,0,0);\nWriteChar4(1,0,0,0);\nWriteChar4(1,19,0,0);\nWriteChar4(7,0,0,0);\nWriteChar4(1,0,0,0);\nWriteChar4(44,0,0,0);\nWriteChar4(12,0,0,0);\nWriteChar4(1,0,0,0);\nWriteChar4(20,0,0,0);\nWriteChar4(100,0,0,0);\nWriteChar4(0,0,0,0);\nWriteChar4(1,11,4,0);\nWriteChar4(0,0,0,0);\nWriteChar4(2,11,7,0);\nWriteChar4(0,0,0,0);\nWriteChar4(0,0,0,0);<\/pre>\n<p>Then there is a remaining BLOB len and no. of menusuites we need to set:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ remaining size 4 bytes\nWriteChar4((Size-44) MOD 256,(Size-44) DIV 256,0,0);\nWriteChar4(20,0,0,0);\n\/\/ no of menusuites\nWriteChar4(MenuSuiteMenu.COUNT MOD 256,MenuSuiteMenu.COUNT DIV 256,MenuSuiteMenu.COUNT DIV 256*256,MenuSuiteMenu.COUNT DIV 256*256*256);<\/pre>\n<p>Then we write our GUIDS to the BLOB:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/guids go here\nIF MenuSuiteMenu.FINDSET THEN REPEAT\nWriteChar4(12,0,0,0);\n\/\/ guid\nStream.WRITE(MenuSuiteMenu.GUID);\nUNTIL MenuSuiteMenu.NEXT = 0;<\/pre>\n<p>Notice writing GUIDs to a stream directly, creates them in their right format, and finally set their permissions:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nIF MenuSuiteMenu.FINDSET THEN REPEAT\nWriteChar4(39,221,4,0);\nIF MenuSuiteMenu.Enabled THEN\nWriteChar4(0,0,0,0)\nELSE\nWriteChar4(1,0,0,0);\nWriteChar4(0,0,0,0);\nUNTIL MenuSuiteMenu.NEXT = 0;\nUserMenuLevel.MODIFY;<\/pre>\n<p>Oh, and you might have wondered, but the WriteChar4 is just a function for writing 4 bytes at the time:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nWriteChar4(Char1 : Char;Char2 : Char;Char3 : Char;Char4 : Char)\nStream.WRITE(Char1);\nStream.WRITE(Char2);\nStream.WRITE(Char3);\nStream.WRITE(Char4);<\/pre>\n<p>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!<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Yesterdays post on assigning MenuSuite Menu&#8217;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&#8217;s Extreme [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[56,3],"tags":[37,77,38,27,51,22,7,39,35,41],"class_list":["post-671","post","type-post","status-publish","format-standard","hentry","category-basic-cal","category-navision","tag-application","tag-navision","tag-guide","tag-how-to","tag-menusuite","tag-object","tag-objects","tag-programming","tag-system-table","tag-tools"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts\/671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/comments?post=671"}],"version-history":[{"count":14,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts\/671\/revisions"}],"predecessor-version":[{"id":1041,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts\/671\/revisions\/1041"}],"wp:attachment":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/media?parent=671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/categories?post=671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/tags?post=671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}