Generate HTML/PDF reports from the cmd-line

I’m trying to integrate DataModeler with the build system and I would like to generate the reports (PDF/HTML) unattended, from the cmd-line. How can that be done?

Hello there,

You cannot generate reports from command line, BUT you can create an external .js script which generates reports and launch it from command line.

First, create a new empty text file and save it as a .js file. Now you have to actually write the script itself.

For example, an HTML report is generated like this (taken from Help | Projects and Models | Scripting and Customization | Automation):


function HTMLReport(Model, System, OutputPath)
{

var ReportRegistrar = System.CreateObject(‘ReportRegistrar’);
ReportRegistrar.DataSource = Model;
var Report = ReportRegistrar.CreateReport(‘BasicHTMLPERReport’+Model.ModelDef.Abbrev, 1 , Model); //1 - HTML

ReportRegistrar.RegisterLayoutClasses(1);

Report.Path = OutputPath;
Report.FileName = ‘Report’;
Report.Language = ‘ENU’;
Report.Kind = ‘HTML’;
Report.Layout = ReportRegistrar.GetLayoutClass(0);
Report.CSS = Report.Layout.CSSList.GetObject(0);
Report.GenerateInfo = false;

Report.Generate();

}
//*****************************************************

var App;
App = new ActiveXObject(“TDM.App”);
var Model = App.OpenModelFromFile(“C:\Models\Videorental.txp”); //Change path
HTMLReport(Model, App.System, ‘C:\Reports\’ ); // Change path


A script to generate PDF report is a bit different:


function PDFReport(Model, System, OutputPath)
{

var ReportRegistrar = System.CreateObject(‘ReportRegistrar’);

ReportRegistrar.DataSource = Model;

var Report = ReportRegistrar.CreateReport(‘BasicRTFPERReport’+Model.ModelDef.Abbrev, 2, Model); //2 - RTF,PDF
Report.Path = OutputPath;
Report.FileName = ‘Report’;
Report.Language = ‘ENU’;
Report.Kind = ‘PDF’;
Report.Frames = true;
Report.Shadow = true;
Report.UseWatermark = false;
Report.Extension = ‘pdf’;
Report.Generate();

}
//*****************************************************

var App;
App = new ActiveXObject(“TDM.App”);
var Model = App.OpenModelFromFile(“C:\Users\lknapek\Documents\Models\Videorental.txp”); //Change path
PDFReport(Model, App.System, ‘C:\Users\lknapek\Documents\Reports’ ); //Change path


If you want, you can look into Reference Guide (Expert Mode Menu | Reference Guide) to learn how to configure more report properties via script.

Once your script is complete, you can launch it from command line using the following command:

Cscript.exe "C:\Path\YourScript.js"

I hope this functionality satisfies your needs.

Regards,

Lukas

I have a question related to this.

I created a custom package where I am able to modify the HTML report that will be generated.
The Metamodel of the package also includes additional properties.

If I run from inside the Application, I can access the properties in my custom package.
If I run from the command line (using the above example), I get an error that the properties is unknown. It shows the exact line in my custom package script, so the package itself is available.

Is there something I need to do related to the custom packages if I run from the command line?