Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.
Topic |
Prev | Next |
Example Template Fragment Script
This JScript returns a row of data in XML format. The XML data can be returned in a document report using a Custom Script Template Fragment.
The script will also display the XML data in the System Output window, so you can easily check the output without running a document report.
!INC Local Scripts.EAConstants-JScript
/*
* Script Name: Document Properties
* Author: Tom O'Reilly
* Purpose: To display the properties of a document
* Date: 02/02/2013
*/
function MyRtfData(objectID)
{
var i;
var xmlDOM = new ActiveXObject("MSXML2.DOMDocument.4.0");
xmlDOM.validateOnParse = false;
xmlDOM.async = false;
var node = xmlDOM.createProcessingInstruction("xml", "version='1.0' encoding='ISO-8859-1'");
xmlDOM.appendChild(node);
var xmlRoot = xmlDOM.createElement("EADATA");
xmlDOM.appendChild(xmlRoot);
var xmlDataSet = xmlDOM.createElement("Dataset_0");
xmlRoot.appendChild(xmlDataSet);
var xmlData = xmlDOM.createElement("Data");
xmlDataSet.appendChild(xmlData);
var xmlRow = xmlDOM.createElement("Row");
xmlData.appendChild(xmlRow);
var xmlName = xmlDOM.createElement("DateGen");
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} today = mm+'/'+dd+'/'+yyyy;
xmlName.text = today;
xmlRow.appendChild(xmlName);
var xmlName = xmlDOM.createElement("TimeGen");
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10)
{
minutes = "0" + minutes
}
xmlName.text = hours + ":" + minutes + " ";
xmlRow.appendChild(xmlName);
var xmlName = xmlDOM.createElement("Author");
xmlName.text = Session.UserName;
xmlRow.appendChild(xmlName);
var xmlName = xmlDOM.createElement("EA_REPOS");
xmlName.text = Repository.ConnectionString;
xmlRow.appendChild(xmlName);
return xmlDOM.xml;
};
Session.Output(MyRtfData(439));
Learn more