Tag: Dynamics NAV

How to list “ProcessOnly” Reports in Dynamics NAV 2009

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:

NameDataTypeSubtypeLength
TempObjectRecordAllObj 
AllObjRecordAllObj 
ObjectMetadataRecordObject Metadata 
XMLDocumentAutomation‘Microsoft XML, v6.0’.DOMDocument60 
InStrInStream  
TempFileFile  
TempFileNameText 250
TempStringText 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) πŸ˜‰

NameDataTypeSubtype
TempObjectRecordAllObj
AllObjRecordAllObj
TempBlobRecordTempBlob
ObjectMetadataRecordObject Metadata
XMLDOMManagementCodeunitXML DOM Management
XmlDocumentDotNetSystem.Xml.XmlDocument.’System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

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);

This blog is available also on Microsoft Dynamics NAV Community

My first blog post… about NAV

It’s been a few years now that I’m reading every single blog post about Dynamics NAV. I learned a lot from all the experts that they share their time with us. Thanks to them, I found answers to a lot of problems I faced in my professional life. Better, I learned enough to overcome challenges on my own.

Lately, I was thinking why not start blogging? So here I am, this is my first blog post. For sure, it is not directly about NAV as I said in the subject; and it will not give you any tip or trick as you expected.

But hey, wait for my next blog post. I already have an idea about its topic… It is about a 100% generic web service client for NAV.

This blog is available also on Microsoft Dynamics NAV Community

© 2022 NAV NAB BLOG

Theme by Anders NorenUp ↑