Skip to main content
Known Participant
November 26, 2014
Answered

Creating a variable that contains the value of the Modification Date (Long) system variable

  • November 26, 2014
  • 1 reply
  • 2386 views

Can someone tell me how to write a script for creating a variable, named DocDate, that contains the value of the Modification Date (Long) system variable? Or to write a script that creates a variable,named DocDate, that contains the current date??? I can't seem to find a whole lot of documentation on ExtendScript script writing.

This topic has been closed for replies.
Correct answer frameexpert

Hi Julee, When you create a user variable in the interface, you can't include the date/time building blocks in the definition. These can only be used in system variables like the Modification Date (Long) system variable. So the question is, why not just use the Modification Date (Long) system variable in your document? What is the purpose of the DocDate user variable? Let me know what you are thinking here, and I can try to help you.

Here are some ExtendScript resources:

My blog: FrameAutomation.com | Making FrameMaker faster and more efficient

Debra Herman's blog: Extending FrameMaker

Russ Ward's extensive samples: FrameMaker ExtendScript Samples - West Street Consulting

-Rick

1 reply

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
November 26, 2014

Hi Julee, When you create a user variable in the interface, you can't include the date/time building blocks in the definition. These can only be used in system variables like the Modification Date (Long) system variable. So the question is, why not just use the Modification Date (Long) system variable in your document? What is the purpose of the DocDate user variable? Let me know what you are thinking here, and I can try to help you.

Here are some ExtendScript resources:

My blog: FrameAutomation.com | Making FrameMaker faster and more efficient

Debra Herman's blog: Extending FrameMaker

Russ Ward's extensive samples: FrameMaker ExtendScript Samples - West Street Consulting

-Rick

Known Participant
November 26, 2014

I use Mif2Go to create my HTML output. I have a DocDate paragraph that contains the Modification Date (Long) system variable and is conditionalized to only appear in the HTML output. I configured Mif2Go to convert the system variable to text, store the text from that variable, and write it in a META tag. However, with the FM12 upgrade (I skipped FM11 but I found out it has the same problem), Mif2Go's TextStore feature stopped working.

I'm trying everything I can imagine to get that date to appear in the HTML META tags. I don't have Jeremy to help me any more and I don't think anyone is interested in fixing Mif2Go because it isn't a feature that anyone else is using...

frameexpert
Community Expert
Community Expert
November 26, 2014

Hi Julie, These tasks are rarely simple, but they are fun anyway. First some background: with a user variable, it is easy to get it's value, because the definition itself is usually its value. Say you have a user variable named "DocDate"; you can run this to get its value:

#target framemaker

var doc = app.ActiveDoc;

varFmt = doc.GetNamedVarFmt ("DocDate");

if (varFmt.ObjectValid () === 1) {

    alert (varFmt.Fmt);

}

Of course, if you have used character format building blocks in the definition, these will be displayed as well. With system variables, things are different. The definitions consist of building blocks and literal text so to get the actual display value, you have to insert the variable somewhere in the document. The code below does exactly that.

#target framemaker

// Make a constant for the points metric value.

var PT = 65536;

var doc = app.ActiveDoc;

alert (getSystemVariableValue ("Modification Date (Long)", doc));

function getSystemVariableValue (varName, doc) {

   

    var masterPage, textFrame, pgf, textLoc, varObj, value = "";

    // Get the first master page in the document.

    masterPage = doc.FirstMasterPageInDoc;

    // Add a temporary text frame to the master page.

    textFrame = doc.NewTextFrame (masterPage.PageFrame);

    textFrame.Width  = 288 * PT;

    // Add the variable to the first paragraph in the temporary text frame.

    pgf = textFrame.FirstPgf;

    textLoc = new TextLoc (pgf, 0);

    varObj = doc.NewAnchoredFormattedVar (varName, textLoc);

    if (varObj.ObjectValid () === 1) {

        // Get the value of the variable.

        value = getText (varObj.TextRange, doc);

    }

    // Delete the temporary text frame.

    textFrame.Delete ();

   

    return value;

}

function getText (textObj, doc) {

   

    // Gets the text from the text object or text range.

    var text = "", textItems, i;

   

    // Get a list of the strings in the text object or text range.

    if (textObj.constructor.name !== "TextRange") {

        textItems = textObj.GetText(Constants.FTI_String);

    } else {

        textItems = doc.GetTextForRange(textObj, Constants.FTI_String);

    }

    // Concatenate the strings.

    for (i = 0; i < textItems.len; i += 1) {

        text += (textItems.sdata);

    }

    return text; // Return the text

}

I have most of the code in a couple of functions for portability. The getText function is a utility function that gets the text from a text object (paragraph, text frame, table cell, etc.) or a text range. The getSystemVariableValue function does the majority of the work needed; the comments should give you an overview of what is happening.

The next step will be to insert the text retrieved on line 7 and insert it into a custom marker. I will do this in another reply. Please test the code above and let me know if you have any questions or comments. Thanks. -Rick