Step 1 - Output model names
Based on our first “Hello ARIS” report we now want to generate an output document which contains ARIS content. Therefore we create a report which lists all selected models with their names and the names of the contained objects.
For using the selected models in your report you have to enter the following code line:
var aModels = ArisData.getSelectedModels();
And now you can iterate over these models and output their names.
To get the names we have to call method “Name()” with the language as parameter. To get this language we us the following code line:
var nLocale = Context.getSelectedLanguage(); // Selected database language
So the complete script looks as follows:
var oOutput = Context.createOutputObject(); // Output object
var nLocale = Context.getSelectedLanguage(); // Selected database language
var aModels = ArisData.getSelectedModels(); // Array of selected models
for (var i = 0; i < aModels.length; i++) {
var oModel = aModels[i]; // Current model
var sModelName = oModel.Name(nLocale); // Name of current model
oOutput.OutputLn(sModelName, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 0);
}
oOutput.WriteReport();Step 2 - Output model and object names
In a further step we want to add the names of all objects which are contained in our models.
To get the objects of the models we use the following method:
var aObjDefs = oModel.ObjDefList(); // All object definitions that have occurrences in the model
So that the report now looks like this:
var oOutput = Context.createOutputObject(); // Output object
var nLocale = Context.getSelectedLanguage(); // Selected database language
var aModels = ArisData.getSelectedModels(); // Array of selected models
for (var i = 0; i < aModels.length; i++) {
var oModel = aModels[i]; // Current model
var sModelName = oModel.Name(nLocale); // Name of current model
oOutput.OutputLn("Model: " + sModelName, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 0);
var aObjDefs = oModel.ObjDefList(); // All object definitions that have occurrences in the model
for (var j = 0; j < aObjDefs.length; j++) {
var oObjDef = aObjDefs[i]; // Current object definition
var sObjName = oObjDef.Name(nLocale); // Name of current object
oOutput.OutputLn("Object: " + sObjName, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10);
}
}
oOutput.WriteReport();You can see: Getting names of objects works in the same way as getting names of models.
Here you can download the entire source code from the "Output models" report.
Note: This article describe how to develop a report in ARIS. See this post for links to similar articles.
Corey Holstege on
Hello Mr. Wieczorek,
First off, thank you for this article, it has been very helpful to me.
I put this report in ARIS today, and while i was testing it i noticed one item. On line 24 of your source code (line 13 in the above picture), you have:
var sObjDef = aObjDefs[i];
When i ran the report with the line like this, it returned the same name for all of the objects on the model. It had the correct number of returned names, they were just all the same.
The line of code should be:
var sObjDef = aObjDefs[i++];
If this line is used, the report, when ran will return all of the correct object names.
Thank you!