MWZ's picture

Much content in ARIS is stored in different attributes. Therefore we want to add further column rows which contains values of the attributes “Identifier” and “Description”:

Model name

Object name

Identifier

Description

<Name of model 1>

 

<ID of model 1>

<Desc. of model 1>

 

<Name of object 1>

<ID of object 1>

<Desc. of object 1>

 

<Name of object 2>

<ID of object 2>

<Desc. of object 2>

 

<…>

<…>

<…>

<Name of model 2>

 

<ID of model 2>

<Desc. of model 2>

 

<Name of object 1>

<ID of object 1>

<Desc. of object 1>

 

<Name of object 2>

<ID of object 2>

<Desc. of object 2>

 

<…>

<…>

<…>

<…>

 

<…>

<…>

Therefore we first write this function to read the attribute value:

function getAttributeValue(oItem, nAttrType) {
    var oAttr = oItem.Attribute(nAttrType, nLocale);    // Attribute with the specified type number in the specified language
    var sAttrValue = oAttr.getValue();                  // Content of the attribute
    return sAttrValue;
}

With method “Attribute()” and the parameters attribute type number and language we get the attribute object and with method “getValue()” of this attribute we get the maintained value.

In the report we use this method as follows:

    var sModelID = getAttributeValue(oModel, Constants.AT_ID);      // ID of current model
    var sModelDesc = getAttributeValue(oModel, Constants.AT_DESC);  // Description of current model    

Our complete script now looks like this:

var oOutput = Context.createOutputObject();     // Output object
var nLocale = Context.getSelectedLanguage();    // Selected database language

oOutput.BeginTable(100, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 0);          
oOutput.TableRow();    
oOutput.TableCell("Model name", 25, "Arial", 10, Constants.C_BLACK, Constants.C_LIGHT_YELLOW, 0, Constants.FMT_BOLD | Constants.FMT_LEFT | Constants.FMT_VTOP, 0);
oOutput.TableCell("Object name", 25, "Arial", 10, Constants.C_BLACK, Constants.C_LIGHT_YELLOW, 0, Constants.FMT_BOLD | Constants.FMT_LEFT | Constants.FMT_VTOP, 0);
oOutput.TableCell("Identifier", 25, "Arial", 10, Constants.C_BLACK, Constants.C_LIGHT_YELLOW, 0, Constants.FMT_BOLD | Constants.FMT_LEFT | Constants.FMT_VTOP, 0);
oOutput.TableCell("Description", 25, "Arial", 10, Constants.C_BLACK, Constants.C_LIGHT_YELLOW, 0, Constants.FMT_BOLD | Constants.FMT_LEFT | Constants.FMT_VTOP, 0);

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
    var sModelID = getAttributeValue(oModel, Constants.AT_ID);      // ID of current model
    var sModelDesc = getAttributeValue(oModel, Constants.AT_DESC);  // Description of current model    

    oOutput.TableRow();    
    oOutput.TableCell(sModelName, 25, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT | Constants.FMT_VTOP, 0);
    oOutput.TableCell("", 25, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT | Constants.FMT_VTOP, 0);
    oOutput.TableCell(sModelID, 25, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT | Constants.FMT_VTOP, 0);
    oOutput.TableCell(sModelDesc, 25, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT | Constants.FMT_VTOP, 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[j];              // Current object definition
        var sObjName = oObjDef.Name(nLocale);   // Name of current object
        var sObjID = getAttributeValue(oObjDef, Constants.AT_ID);       // ID of current object
        var sObjDesc = getAttributeValue(oObjDef, Constants.AT_DESC);   // Description of current object    
        
        oOutput.TableRow();    
        oOutput.TableCell("", 25, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT | Constants.FMT_VTOP, 0);
        oOutput.TableCell(sObjName, 25, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT | Constants.FMT_VTOP, 0);
        oOutput.TableCell(sObjID, 25, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT | Constants.FMT_VTOP, 0);
        oOutput.TableCell(sObjDesc, 25, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT | Constants.FMT_VTOP, 0);

    }    
}
oOutput.EndTable("", 100, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, 0, Constants.FMT_LEFT | Constants.FMT_VTOP, 0);
oOutput.WriteReport();

function getAttributeValue(oItem, nAttrType) {
    var oAttr = oItem.Attribute(nAttrType, nLocale);    // Attribute with the specified type number in the specified language
    var sAttrValue = oAttr.getValue();                  // Content of the attribute
    return sAttrValue;
}

Here you can download the entire source code from the "Output models with attributes" report.

Note: This article describe how to develop a report in ARIS. See this post for links to similar articles.

Tags: ARIS Report