Pages: 1
Print
Author Topic: setting modified attribute of revised element to last save date automatically  (Read 2039 times)
IF
Member

Posts: 80


« on: January 19, 2015, 05:17:21 PM »

Is there a way to automatically set the value of the modified attribute of the revised element inside the critdates element  to the file's save date in XMetal Author Enterprise 8? Thanks.
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #1 on: January 19, 2015, 07:02:51 PM »

A script similar to the following would probably do what you need:

Code:
//XMetaL Script Language JScript:
var rng = ActiveDocument.Range;
rng.MoveToDocumentStart();
if(rng.MoveToElement("revised")) {
var d = new Date;
rng.ContainerAttribute("modified") = d.toUTCString();
}

To get it to run at save you can put it into the appropriate events in a Startup MCR file. Note that as written this will run for all document types (not just DITA) so if that will be an issue for you additional checks would need to be implemented. For someone only working with DITA I'm pretty sure that should not be a problem. For someone working with other schemas that don't define an element named "revised" it should not be an issue either. Note that adding things to the system this way is fairly safe since we're not redefining any of the standard DITA behaviours (we're just doing something extra) but officially this type of change isn't really supported for the DITA authoring solution which is considered closed.

If you are running any 3rd party code with XMetaL Author Enterprise (other than our provided DITA solution or our integrations with Documentum or Sharepoint) be sure to check with the creator to see that this will not interfere with anything their code does. This would include CMS integrations but could include any other code provided to you that you add to the XMetaL Author Enterprise installation (either by hand or by running a 3rd party installer).

Here's what the MCR file might look like. Make sure you test it thoroughly before putting it into production as I have done only the very minimum, and of course can only test in my own environment.

Code:
<?xml version="1.0"?>
<!DOCTYPE MACROS SYSTEM "macros.dtd">

<MACROS>

<MACRO name="On_Macro_File_Load" lang="JScript" hide="true"><![CDATA[
function setRevisedModifiedDate() {
var rng = ActiveDocument.Range;
rng.MoveToDocumentStart();
if(rng.MoveToElement("revised")) {
var d = new Date;
rng.ContainerAttribute("modified") = d.toUTCString();
}
}
]]></MACRO>

<MACRO name="On_Document_Save" lang="JScript" hide="true"><![CDATA[
setRevisedModifiedDate();
]]></MACRO>

<MACRO name="On_Document_SaveAs" lang="JScript" hide="true"><![CDATA[
setRevisedModifiedDate();
]]></MACRO>

</MACROS>
Logged
IF
Member

Posts: 80


« Reply #2 on: January 20, 2015, 12:10:53 PM »

Wonderful. Works perfectly. Thanks!
Logged
Pages: 1
Print
Jump to:  

email us