ExtendScript of the Week: Find/Change Cross Reference Formats / Conditional Tags / Variables

This week in “Extend Script of the Week” initiative we will showcase an extend script which will Find/Change Cross-Reference Formats (aka “XREF Formats), Conditional Tags and Variables on the Body page of a FrameMaker document. This script demonstrates how to use ExtendScript to traverse a document, find Xrefs/Conditional Tags/Variables and then change them or delete them.

Information about the Scripts

  • The zip contains seven ExtendScripts:

    • ChangeFormatMenu.jsx loads the menu and calls the function to execute the work flow.

    • ChangeConditionalFormat.jsx is used to change the conditional tag.

    • ChangeVariable.jsx is used to change the variable.

    • ChangeXrefFormat.jsx is used to change the format of the XRef.

    • ChangeFormatUtils.jsx contains various utilty functions.

    • ChangeFormatUI.jsx prepares the UI to be launched in FM.

    • BookIterator.jsx is used to iterate over the book.

  • The script works on FM/MIF, nested books and its components as well as on the hierarchical components.

  • Any XML file, dita or map which is a part of the book is left untouched.

  • The script will pick up the format/variable/tag from the document or the first non generated component of book.

  • If run on a book, all unopened components will be opened silently and will be modified, saved and closed without asking. All opened components will be modified and left visible.

  • User has an option to include System Variables, by default it has been excluded as it makes the list quite long.

  • User also has an option to delete the conditional tag/variable/xref format which was replaced after the changes are made.

  • At the end the user will be notified about the number of changes made in the document.

Steps to Install

  • Download the zip file from ChangeFormat.

  • Unzip the files and copy “ChangeFormatMenu.jsx” and “ChangeFormat” folder in startup folder located at “C:\Program Files\Adobe\AdobeFrameMaker10\startup\”

How to use the Script

  • Launch FrameMaker

  • Open a Book File or FM/MIF File eg : Doc1_10.fm

  • Run Change Formats from “File -> Utilities -> Change Formats…

  • This will run the script and ask you for inputs for find/change.

  • Click on the radio button to choose the object you want to change.

    FrameMaker ExtendScript – Find/Change Cross-Reference Formats, Variable Formats, Conditional Tags

  • Choose the value to be changed in ‘Find’ dropdown.

  • Choose the value to be applied in ‘Replace With’ dropdown.

  • Click on Change button.

    FrameMaker ExtendScript – Find/Change Cross-Reference Formats, Variable Formats, Conditional Tags


I hope this will prove useful to many folks and you can add extra functionality as per your requirements to these scripts to make it even more powerful

(Resources: ChangeFormats)

Bharat Prakash

Bharat Prakash

Bharat Prakash is the Product Solution Consultant for the Technical Communication unit at Adobe and has more than a decade’s experience in software development, testing and consulting. He has extensive experience in end-to-end deployment of features from conception to delivery with wide exposure to different SDLC models. Bharat is an expert in Structured Authoring and various industry standards like DITA and MathML.

20 thoughts to “ExtendScript of the Week: Find/Change Cross Reference Formats / Conditional Tags / Variables”

  1. Hi,

    I am new to scripting. I am using extend script. I need a script for fixing cross references in my document/book. I am using unstructured Frame Maker version 10.

    1. Hi Bharat,

      Can you please provide some guidance on automating (using extendscript) ‘fixing broken cross reference’ for both within the chapter and in the book.


      1. Hi Isha,

        if a cross-reference is broken it means, that the “destination” (the paragraph etc. where the cross-reference is pointing to), does no longer exist / cannot be found. There is a myriad of possibilities why this can happen: An author might have deleted the target destination in the text, or the whole file might have been deleted, or renamed, or is on an inaccessible network file, or files were moved around on the hard drive, or …

        Unfortunately, there is no secret “Fix all my problems” line of code in ExtendScript 😉
        You will have to dig a little bit deeper into it: Why are the cross-references broken? What is the reason? And then think about how to solve that. If there is a clear “pattern” on all your broken cross-references, it might be possible to write code to fix that. The best way will be to write a post in the Adobe Community “FrameMaker Scripting” forum: https://forums.adobe.com/community/framemaker/extendscript?view=overview


  2. Used this on FM11 to change all uses of an xref format. But am having mixed results. If no files in the book are open, then the list if xrefs just shows one entry: TemplateName. If I open a file, it finds actual format names. But when I run the utility, it won’t find anything. Or sometimes it does find some. Every time I run it on the same book it varies. The first time, it found tons, and I thought it was done. But it missed a lot. I’m not really sure it did change anything now.

  3. Hi I tried running this script as you stated above, but FM10 throws the following console error: 
    Script Error : Error Message      : null is not an objectScript, Line#   : C:Program Files (x86)AdobeAdobeFrameMaker10startupChangeFormatChangeFormatUI.jsx,  81

    This seems to point to the following line of code in ChangeFormatUI.jsx:


    Is it okay to declare varbl as:

    var varbl = new Object();


    1. Hi Roman,

      I have uploaded the Latest zip containing the fixes. Kindly download these files from ‘Resources’.


      1) Problem handling the flow for changing para tags
      2) There was an extra check for checking system variables . This should solve of FM freezing for some folks.
      3) Previously the script did not work on hidden tags but now it does

      Bharat Prakash
      FrameMaker Engineering

  4. Hi,

    For some reason, it does not work for me. When I run the script, Framemaker freezes. BTW, I fixed the var NewCommand = DefineCommand.

      1. Hi Anh,

        Thanks for using the script. Kindly send me some sample files so that i can isolate the issue.

        Bharat Prakash(bharatp@adobe.com)
        FrameMaker Engineering

          1. Hi Anh,

            I have fixed the issue and mailed you the updated scripts. Kindly let me know if there are any more issue.

            Bharat Prakash(bharatp@adobe.com)
            FrameMaker Engineering

    1. Hi Mike ,

      Thanks for pointing it out. Kindly replace the following statement in ChangeFormatMenu.jsx and it should take care of the problem.

      Original :: var NewCommand = DefineCommand(1,”Change Formats…”,”Change Formats…”)

      New :: var NewCommand = DefineCommand(1,”Change Formats…”,”Change Formats…”,””)

  5. Hi Wim,

    Thanks for the comment. I have not come across this issue.
    Changing conditional tags in structured FM might lead to issues sometimes ,but changing Xref format/Variable should not be a problem.
    Could you send me a sample file on which you facing the issue. My email is bharatp@adobe.com.

    Bharat Prakash

Leave a Reply to Isha Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.