Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

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.

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)

     {

          if(reporting.NewDocument(""))

          {

               if(!reporting.LoadDocument("<filename>"))

               {

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

               }

               return reporting.GetDocumentAsRTF();

          }

     }

}

Create a Document Script Fragment

Step

Action

See also

1

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

Document Templates Creating a Template Fragment

2

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

The 'Document Options' dialog displays.

3

Select the 'Custom Query' page.

4

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

5

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

6

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:

     Main(#OBJECTID#);

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

7

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

Setting Sections for Reporting

8

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

9

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.

Notes

  • 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