Sunday, 18 January 2009

Where is that MenuSuite option in NAV 2009? Part 2.

In my first post on the MenuSuite search, I discovered that in NAV 2009 we can get at the MenuSuite through a blob field on the Object Metadata table.

In this post, I'll go one step further to see if we can start to do something with the blob.

The first thing I wanted to know is: do I need to worry about merging the various MenuSuites? When the MenuSuite is exported as text it contains only the differences that should be applied to the previous MenuSuite. For example 1080 (Partner Level) stores the differences that need to be applied to 1020 (Regional level) which in turn stores the differences that need to be applied to 1010 (Dept – MBS level).

I used a text comparison tool to compare my 1080 XML export to my 1020 XML and I can see that the 1080 is the full combined MenuSuite – perfect! This means I don’t have to worry about merging these files together. If I search for the items I want in the MenuSuite with the highest number, I will be looking at the correct menu structure.

Next I need to know what I am looking for in the XML file. If I take a look through the 1080 file, I can see we are looking for an Actions node with an xsi:type attribute of “ActionDefinition”. This will give me the node that is going to run an option. Within this node I can see there is a CaptionML attribute that I can search to try and match the string I am looking for.

My next programming task is to see if I can get the XML document loaded into an XMLDOM automation control inside NAV. Once again, this was a lot easier than I thought it was going to be. I'm not doing much with the XMLDOM, simply loading it and then saving it again so I can check everythig is working. Here's the code:
OBJECT Codeunit 91360 Export MenuSuite Objects
{
OBJECT-PROPERTIES
{
Modified=Yes;
Version List=;
}
PROPERTIES
{
OnRun=VAR
l_ObjectMetadata@1000000004 : Record 2000000071;
l_XMLDoc@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v4.0'.DOMDocument";
l_InStream@1000000001 : InStream;
BEGIN
// MenuSuite items in the RoleTailored client are stored in the range 1000..1999
// They map to the Classic client numbers but with 1000 added to the number.

CREATE(l_XMLDoc, FALSE, FALSE);

l_ObjectMetadata.SETRANGE("Object Type", l_ObjectMetadata."Object Type"::MenuSuite);
l_ObjectMetadata.SETRANGE("Object ID", 1000, 1999);

// The XML document for the highest number contains all nodes not just the changes.
// so we only need to do a FINDLAST
IF NOT l_ObjectMetadata.FINDLAST THEN
ERROR('Something went wrong. There was no Object Metadata for the RoleTailored MenuSuites.\'+
'This sample only works with NAV 2009.');

l_ObjectMetadata.CALCFIELDS(Metadata);

l_ObjectMetadata.Metadata.CREATEINSTREAM(l_InStream);

l_XMLDoc.load(l_InStream);

// Just to check to see if I have my XMLDoc loaded correctly, I'm going to save it and
// then open it in my browser.
l_XMLDoc.save(TEMPORARYPATH+STRSUBSTNO('XMLDOM_%1.xml',l_ObjectMetadata."Object ID"));
HYPERLINK(TEMPORARYPATH+STRSUBSTNO('XMLDOM_%1.xml',l_ObjectMetadata."Object ID"));
END;

}
CODE
{

BEGIN
END.
}
}

No comments: