Book a Demo
Prev Next

How to Define a Document Script Fragment

You can create a Template Fragment to return data from a Document Script. You do this by creating a Script that returns either an empty string or a string that contains raw RTF. You add a reference to this Script in the 'Template Fragment Document Options', and the returned RTF string is added to the generated document.

An Example Script

This is an example of a Document Script you might create:

!INC Local Scripts.EAConstants-JScript

function main()


     var reporting as EA.DocumentGenerator;

     reporting = CreateDocumentGenerator();

     if(reporting != null)






                    Session.Output( "Error: " + reporting.GetLastError() );


               return reporting.GetDocumentAsRTF();




Create a Document Script Fragment



See also


Open or create a Template Fragment in the Document Template Editor.

Document Templates Creating a Template Fragment


In the Document Template Editor, right-click on the Template background and click on the icon.

The 'Document Options' dialog displays.


Select the 'Custom Query' page.


In the 'Template Fragment type' panel, select the 'Document Script' radio button.


A field displays to the right of the radio button panel; click on the drop-down arrow and select the Model Script to be used by your Template Fragment.

Create Search Definitions


In the main text field on the tab, type the entry point of your Script that returns the RTF Text.

For example, in JScript, the call to your script would be in the form:


(For VBScript, omit the semi-colon at the end.)


Click on the OK button to close the 'Document Options' dialog.

Setting Sections for Reporting


In the 'Document Template Editor', in the 'Sections' panel, select the 'Custom' checkbox to create the 'Custom' section.


Save the Template Fragment, and add a call to it in a normal document template.

When run, this will return an RTF string that is incorporated into the generated document.


  • The Model Search macros #..# can be used in the call statement that calls the procedure, but not in the procedure code; in your call statement you can reference model details using:
         -  #OBJECTID# to return the ID of the element currently being processed by the document template
         -  #PACKAGEID# and #Package# to return the ID of the Package currently being processed by the
            document template
         -  #Branch# to get the IDs of the child Packages of the current Package being processed, working
            recursively down to the lowest level of sub-Package; this is only valid when processing a Package,
            elements return a 0 value

Learn more