I was doing my daily NAV tour on Mibuso and NAV Community forums when I spotted the following question:
I have about 300 new reports in my nav database and I need to write down the names of only those that are not ProcessingOnly. Do you know any smart way how to do this quick?
A member suggested an answer. But, it applies to NAV new versions only (2015 and later).
I could not resist the challenge. Hence my blog post to suggest a solution that applies for all old NAV versions (all versions might be a big word because I tested the code in a 2009 R2 database only ;))
Let’s get straight to the point. Here are the variables I used:
Name | DataType | Subtype | Length |
---|---|---|---|
TempObject | Record | AllObj | |
AllObj | Record | AllObj | |
ObjectMetadata | Record | Object Metadata | |
XMLDocument | Automation | ‘Microsoft XML, v6.0’.DOMDocument60 | |
InStr | InStream | ||
TempFile | File | ||
TempFileName | Text | 250 | |
TempString | Text | 1024 |
And the code:
ObjectMetadata.SETRANGE("Object Type", ObjectMetadata."Object Type"::Report);
// Filter On report ID if needed
// ObjectMetadata.SETFILTER("Object ID", 'MyFilter');
IF ObjectMetadata.FINDSET THEN
REPEAT
ObjectMetadata.CALCFIELDS(Metadata);
IF ObjectMetadata.Metadata.HASVALUE THEN BEGIN
TempFileName := DELCHR(TEMPORARYPATH + FORMAT(CREATEGUID) + '.xml', '=', '{}-');
TempFile.CREATE(TempFileName);
TempFile.WRITEMODE := TRUE;
TempFile.TEXTMODE := TRUE;
ObjectMetadata.Metadata.CREATEINSTREAM(InStr);
InStr.READTEXT(TempString, 1024);
WHILE NOT InStr.EOS DO BEGIN
CLEAR(TempString);
InStr.READTEXT(TempString, 1024);
TempFile.WRITE(TempString);
END;
TempFile.CLOSE;
IF ISCLEAR(XMLDocument) THEN
CREATE(XMLDocument);
XMLDocument.load(TempFileName);
FILE.ERASE(TempFileName);
// 1 is ProcessOnly, 0 Others
IF XMLDocument.selectSingleNode('Report/ProcessingOnly').text = '0' THEN BEGIN
AllObj.GET(ObjectMetadata."Object Type", ObjectMetadata."Object ID");
TempObject.INIT;
TempObject.TRANSFERFIELDS(AllObj);
TempObject.INSERT;
END;
END;
UNTIL ObjectMetadata.NEXT = 0;
FORM.RUNMODAL(FORM::"All Objects", TempObject);
And of course, the code adapted for NAV new versions (NAV 2016 in my test) 😉
Name | DataType | Subtype |
---|---|---|
TempObject | Record | AllObj |
AllObj | Record | AllObj |
TempBlob | Record | TempBlob |
ObjectMetadata | Record | Object Metadata |
XMLDOMManagement | Codeunit | XML DOM Management |
XmlDocument | DotNet | System.Xml.XmlDocument.’System.Xml, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b77a5c561934e089′ |
And the code:
ObjectMetadata.SETRANGE("Object Type", ObjectMetadata."Object Type"::Report);
// ObjectMetadata.SETFILTER("Object ID", '3');
IF ObjectMetadata.FINDSET THEN
REPEAT
ObjectMetadata.CALCFIELDS(Metadata);
IF ObjectMetadata.Metadata.HASVALUE THEN BEGIN
TempBlob.Blob := ObjectMetadata.Metadata;
XMLDOMManagement.LoadXMLDocumentFromText(TempBlob.ReadAsText('', TEXTENCODING::UTF8), XmlDocument);
IF XMLDOMManagement.FindNodeText(XmlDocument, 'Report/ProcessingOnly') = '0' THEN BEGIN
AllObj.GET(ObjectMetadata."Object Type", ObjectMetadata."Object ID");
TempObject.INIT;
TempObject.TRANSFERFIELDS(AllObj);
TempObject.INSERT;
END;
END;
UNTIL ObjectMetadata.NEXT = 0;
PAGE.RUNMODAL(PAGE::"All Objects", TempObject);