Using Script Fragments

A script fragment contains a script object. A script object contains reusable JavaScript functions or values that are stored separately from any particular form object, such as a date parser or a web service invocation. Typically, you use the script objects to create custom functions and methods that you want to use in many locations on a form. Using script objects reduces the overall amount of scripting required to perform repetitive actions.

Script fragments include only script objects that appear as children of variables in the Hierarchy palette. Fragments cannot contain scripts that are associated with other form objects, such as event scripts like validate, calculate, or initialize.

You create a script fragment from the Hierarchy palette.

You edit script fragments the same way as other fragments.

Script fragment properties

When you select a script fragment, the Script Object tab in the Object palette displays the fragment properties.

Source File

Sets the source file for the fragment reference. This property is visible only when the selected object is a fragment reference.

Fragment Name

Sets the name of the fragment. You can click the Frag Info button  to view the fragment information.

This property is visible when a fragment reference or a fragment that is defined in a source file is selected. When the selected object is a fragment reference, this property does not appear if the source file is not specified. The Fragment Name list includes all the fragments in the specified source file. The Custom option directly supports setting a SOM expression or an ID value as the fragment reference and supports the implementation in the XML Forms Architecture.

To create a script fragment

You can create a script fragment of common functions that you can reuse in multiple forms. To create a script fragment, you create a script object that contains the functions that you want to reuse in multiple form designs. The script fragment can include only one script object.

  1. Create a script object.

  2. In the Hierarchy palette, right-click the script object and select Fragments > Create Fragment.

    Note: You can also create a script fragment by dragging the script object from the Hierarchy palette to the Fragment Library palette.
  3. To use a different fragment name, in the Name box, type a name for the fragment.

  4. (Optional) In the Description box, type a description of the fragment.

  5. Select a method for creating the fragment:

    • To define the fragment in a separate XDP file that is stored in the Fragment Library, select Create New Fragment In Fragment Library. In the Fragment Library list, select the Fragment Library in which to save the fragment file. To use a different file name, in the File Name box, type the file name for the fragment. If you do not want to replace the selection with the new fragment, deselect Replace Selection With Reference To New Form Fragment.

    • To define the fragment in the current file, select Create New Fragment in Current Document.

  6. Click OK.

To insert a script fragment

You can use script fragments to reuse JavaScript functions in multiple forms. When creating a form design, you insert a reference to an existing script fragment and the fragment appears in the form design.

You cannot insert a fragment in an XFAF document.

Note: To preview the fragments in the Fragment Library palette, select Show Preview Pane from the palette menu.

To insert a script fragment from the Fragment Library palette:

  1. In the fragment library, select the script fragment.

  2. Drag the fragment to a subform or variables object in the Hierarchy palette.

To insert a script fragment from the Insert menu:

  1. Select Insert > Fragment.

  2. Navigate to the file that contains the fragment.

  3. Select the file and click OK. The fragment appears as a child of the variables object in the root subform

// Ethnio survey code removed