Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: Nick Wh on March 13, 2013, 12:23:42 am
-
There's lots of great html fragments that can be substituted when generating html reports. Things like "#CREATEDATE#, "MODDATE" etc. These are for properties of EA objects.
What I want is something that will put the date the html is generated into any page - e.g. on Diagrams, Objects, etc.
It would be great if there was simply a global #TODAYDATE# or similar. Or perhaps a guru knows how to modify the customisable Javascript that generates html, to put the date into certain places?
I've managed to put some javascript into the 'Body - Diagram' and 'Body - Object' html, but this simply gets inserted as javascript into the html, thus is evaluated every time the pages is displayed - always returning the current date.
Any hints appreciated!
Nick
-
Hi Nick
Try adding the following piece of Javascript (without the ") to the required HTML templates
[highlight]"<script type="text/javascript" >
<!--
document.write(document.lastModified);
// -->
< /script>"[/highlight]
It outputs in American format (or at least if did for me), but you may find some Javascript function to format the date.
this makes sense!
All the best
Phil
-
Hi Nick
Here's a better script with formatting into dd/mm/yyyy format
[highlight]"<script type="text/javascript">
<!--
var generated = new Date(document.lastModified);
var day = generated.getDate();
var month = generated.getMonth() + 1;
var year = generated.getFullYear();
document.write("Generated on: " + day + '/' + (month <= 9 ? '0' + month : month) + '/' + year);
// -->"[/highlight]
Enjoy!
All best
Phil
-
Ah, I had pretty much the same code, but with the line :
new Date();
instead of:
new Date(document.lastModified);
I can see what it should do - looks most promising. Will confirm tomorrow whether it has worked.
PS I also prefer your more succint code !
Thanks Phil,
Nick
-
Thanks Phil,
confirmed - that code works perfectly!
Added it into the 'Body - Diagram' and 'Body - Object' html templates. This seems to cover pretty much all the web pages we use - certainly enough for support purposes - to know which version of a website people are using.
cheers,
Nick
-
I'm looking for the same functionality (insert a "generated on" date that won't be updated automatically later), but for RTF reports. Any suggestions?
-
I guess that would be the 'current date' field available from the context menu 'Insert' in the RTF template editor?
-
That's what I used in the report template to insert the value into the RTF report. but when the report is opened (in Word), the field gets updated automatically.
-
I thought it didn't but you're right :(
If you use script and the EA API to generate the RTF: i use custom data fields in the RTF template (insert->data field) and then the EA api DocumentGenerator.ReplaceField to include variable content. Works as expected.
If you use the RTF generator dialog in EA i think you need to define a project constant for the data field, but then that will have a fixed value so unless you are willing to update that every time you generate a document it won't be of much help.
If you consider scripting RTF generation: i wrote a demo on how to do that in the community resources (http://community.sparxsystems.com/resources/scripts/script-creates-rtf-document-using-documentgenerator-api).
best regards,
Paulus