Followed this instruction here
Created my own document template fragment
wiht custom field inside.
Binded custom script to it (code will be below)
Created document
template which contain my document template fragment
(in template fragment inside custom
tag I added custom fields like Author
and TimeGen
)
Used document generation on it but what I get is an empty document! Why this is happen?
I got Sparx Ea 12 version
Script code (copied from example here)
function MyRtfData(objectID) {
var i;
var xmlDOM = new ActiveXObject("Microsoft.XMLDOM");
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;
};
When I running it in debugging mode it seems like okay, it outputs some xml structure, but when I generate document - I got just emtpy sheet
UPD:
Now I get rtf error, and system output just empty
UPD2:
When I debug it it output valid XML
Problem is solved! By that I mean that I can generate documents with custom fields using
template framents + scripts
mechanism.What I've done (long story short - started everything from scratch):
JScript
file (the one above code was contained inJavascript
file, maybe it was the reason)fragment template
, made customAutor
field theretemplate
, added there myfragment template