Adobe® LiveCycle® Designer 8.0 Scripting Basics for Microsoft® Windows®
Edition 1.0, November 2006
If this guide is distributed with software that includes an end user agreement, this guide, as well as the software described in it, is furnished
under license and may be used or copied only in accordance with the terms of such license. Except as permitted by any such license, no part
of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, recording,
or otherwise, without the prior written permission of Adobe Systems Incorporated. Please note that the content in this guide is protected
under copyright law even if it is not distributed with software that includes an end user license agreement.
The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as a
commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or
inaccuracies that may appear in the informational content contained in this guide.
Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law. The
unauthorized incorporation of such material into your new work could be a violation of the rights of the copyright owner. Please be sure to
obtain any permission required from the copyright owner.
Any references to company names and company logos in sample material or sample forms included in this software are for demonstration
purposes only and are not intended to refer to any actual organization.
Adobe, Adobe logo, Acrobat, LiveCycle, and Reader are either registered trademarks or trademarks of Adobe Systems Incorporated in the
United States and/or other countries.
JavaScript is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries.
Microsoft and Windows are either trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.
All other trademarks are the property of their respective owners.
This product includes software developed by the Apache Software Foundation (http://www.apache.org/).
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA.
Notice to U.S. Government End Users. The Software and Documentation are “Commercial Items,” as that term is defined at 48 C.F.R. ß2.101,
consisting of “Commercial Computer Software” and “Commercial Computer Software Documentation,” as such terms are used in 48 C.F.R.
ß12.212 or 48 C.F.R. ß227.7202, as applicable. Consistent with 48 C.F.R. ß12.212 or 48 C.F.R. ßß227.7202-1 through 227.7202-4, as applicable,
the Commercial Computer Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users
(a) only as Commercial Items and (b) with only those rights as are granted to all other end users pursuant to the terms and conditions herein.
Unpublished-rights reserved under the copyright laws of the United States. Adobe Systems Incorporated, 345 Park Avenue, San Jose, CA
95110-2704, USA. For U.S. Government End Users, Adobe agrees to comply with all applicable equal opportunity laws including, if
appropriate, the provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance Act of
1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1 through 60-60,
60-250, and 60-741. The affirmative action clause and regulations contained in the preceding sentence shall be incorporated by reference.
Who should read this guide? ..................................................................................................................................................... 6
Purpose and scope ........................................................................................................................................................................ 6
Related documentation............................................................................................................................................................... 7
1About Scripting in LiveCycle Designer ...................................................................................... 9
How scripting works...................................................................................................................................................................... 9
Objects that support calculations and scripts ...................................................................................................................10
2Configuring LiveCycle Designer Workspace for Scripting .....................................................11
About the Script Editor............................................................................................................................................................... 11
To show the Script Editor ..........................................................................................................................................................12
To change from single-line to multiline view ....................................................................................................................12
To set the default scripting language...................................................................................................................................12
To set the default processing application...........................................................................................................................13
To display Arabic, Hebrew, Thai, and Vietnamese characters......................................................................................13
Using the workspace to debug calculations and scripts ............................................................................................... 14
3Creating Calculations and Scripts ............................................................................................ 16
About creating calculations and scripts...............................................................................................................................16
Naming conventions for form design objects and variables ....................................................................................... 16
Choosing a scripting language ...............................................................................................................................................17
To create a calculation or script ..............................................................................................................................................18
To find text or other items ........................................................................................................................................................18
To replace text or other items..................................................................................................................................................19
To use statement completion to create calculations and scripts...............................................................................19
To insert object reference syntax automatically...............................................................................................................20
Determining when to run your calculation or script.......................................................................................................20
To view scripting events and scripts .....................................................................................................................................21
Determining where to run your calculation or script......................................................................................................23
Testing and debugging calculations and scripts..............................................................................................................23
About events..................................................................................................................................................................................24
Types of events .............................................................................................................................................................................24
Process events...............................................................................................................................................................................24
List of events ..................................................................................................................................................................................28
enter event ...............................................................................................................................................................................31
full event....................................................................................................................................................................................33
Differences between FormCalc and JavaScript functions.............................................................................................41
Using FormCalc.............................................................................................................................................................................47
About using FormCalc..........................................................................................................................................................47
Using built-in functions .......................................................................................................................................................47
To attach a FormCalc function to an object.................................................................................................................48
Built-in function syntax........................................................................................................................................................ 48
Using JavaScript............................................................................................................................................................................51
About using JavaScript ........................................................................................................................................................ 51
Creating scripts using JavaScript......................................................................................................................................51
To attach a JavaScript script to an object......................................................................................................................52
About variables.............................................................................................................................................................................53
To define a text variable............................................................................................................................................................. 53
To view a text variable definition ...........................................................................................................................................54
To delete a text variable.............................................................................................................................................................54
Using variables in calculations and scripts..........................................................................................................................54
7Referencing Objects in Calculations and Scripts..................................................................... 56
About referencing objects in calculations and scripts....................................................................................................56
Referencing object properties and values ..........................................................................................................................56
Referencing unnamed and repeated objects ....................................................................................................................58
Referencing the current object ...............................................................................................................................................60
8Creating and Reusing JavaScript Functions ............................................................................ 65
About the script object ..............................................................................................................................................................65
To create a script object.............................................................................................................................................................65
To add script to a script object................................................................................................................................................65
To reference JavaScript functions stored in a script object..........................................................................................66
Adobe LiveCycle Designer
LiveCycle Designer Scripting Basics 5
9Debugging Calculations and Scripts........................................................................................ 67
About debugging calculations and scripts.........................................................................................................................67
Providing debugging feedback using the messageBox method...............................................................................67
To enable the JavaScript Debugger for LiveCycle Designer.........................................................................................68
To prevent the JavaScript Debugger from disappearing in LiveCycle Designer..................................................69
Executing scripts in the JavaScript Console .......................................................................................................................69
Providing debugging feedback using the JavaScript Console....................................................................................70
10 Working with a Host Application ............................................................................................. 71
About working with a host application................................................................................................................................71
Comparing the host scripting model functionality .........................................................................................................72
11 Working with the Event Model ................................................................................................. 74
About the event model..............................................................................................................................................................74
Event model properties and methods..................................................................................................................................74
12 Moving from Scripting in Acrobat to LiveCycle Designer ......................................................76
About moving from scripting in Acrobat to LiveCycle Designer................................................................................76
Converting Acrobat forms that contain scripts.................................................................................................................77
Using JavaScript objects from Acrobat in LiveCycle Designer ....................................................................................77
JavaScript objects from Acrobat supported in LiveCycle Designer...........................................................................78
13 Examples of Common Scripting Tasks..................................................................................... 91
About the scripting examples .................................................................................................................................................91
Changing the background colors of fields, fillable areas, and subforms.................................................................91
Hiding and showing objects ....................................................................................................................................................93
Changing the visual properties of an object on the client............................................................................................97
Getting the current or previous value of a drop-down list ........................................................................................ 100
Adjusting the height of a field at run time....................................................................................................................... 102
Setting a field as required at run time ............................................................................................................................... 102
Calculating the field sums...................................................................................................................................................... 103
Highlighting fields in response to form filler interaction ........................................................................................... 104
Resetting the values of the current subform................................................................................................................... 107
Changing the presence of a form design object ........................................................................................................... 108
Using the properties of the instance manager to control subforms...................................................................... 109
Using the methods of the instance manager to control subforms......................................................................... 110
Using the instance manager to control subforms at run time.................................................................................. 112
14 Index .........................................................................................................................................117
Preface
Introduction
Welcome to the Adobe® LiveCycle® Designer Scripting Basics guide. This scripting guide is designed to
provide you with an overview of how you can use LiveCycle Designer calculations and scripts to develop
and enhance forms created in LiveCycle Designer. For example, you can use calculations and scripts to
perform the following actions:
● Change the behavior and appearance of objects at run time
● Control the presentation of field values
● Provide interaction with form fillers using dialogs and visual cues
● Automate form filling
● Control the hosting environment
● Interact with Web Services
● Interacting with databases and populate forms with data from data sources
Here you will find detailed information and examples of what the LiveCycle Designer calculation and
scripting capabilities are and how to access them, as well as descriptions of the usage of the
LiveCycle Designer Script Editor. LiveCycle Designer calculations and scripts are a powerful way to
enhance and extend your LiveCycle Designer forms.
Who should read this guide?
This guide is intended for form authors and form developers interested in using calculations and scripts to
extend their LiveCycle Designer forms. However, it is assumed that you have a working knowledge of
scripting languages, especially JavaScript, as well as object models. You should also be familiar with
Adobe Acrobat® Professional or Acrobat Standard, and be comfortable working in a structured XML
environment.
Purpose and scope
The purpose of this guide is to provide you the following information:
● An introduction to using LiveCycle Designer calculations and scripts to extend your forms
● Easily understood, detailed information and examples of the LiveCycle Designer calculation and
scripting features
● References to other resources where you can learn more about LiveCycle Designer scripting and
related technologies
After reading this guide, you should be equipped to start using LiveCycle Designer calculations and
scripts. During the development process, you will find that the descriptions and examples in this guide will
provide you with enough direction and background to enable you to successfully complete your projects.
6
Adobe LiveCycle DesignerPreface
LiveCycle Designer Scripting Basics Related documentation 7
Related documentation
Adobe has a wide variety of resources dedicated to LiveCycle Designer scripting focused at both the form
author and the form developer audiences. The following illustration and section outline the different
resources available and where to find them.
Roadmap
The roadmap document is the starting point for learning about the scripting resources available to you.
Follow the paths and discover the different sources of scripting information and how they can help you
meet your scripting needs.
LiveCycle Designer Help
The LiveCycle Designer Help contains detailed information on using the product, including information on
using calculations and scripts, and should be the first place you search for information on any topics
related to LiveCycle Designer.
LiveCycle Designer Scripting Basics guide
This guide provides an overview of creating calculations and scripts for use with LiveCycle Designer. This
guide is intended to help you create calculations and scripts using FormCalc and JavaScript.
Adobe LiveCycle DesignerPreface
LiveCycle Designer Scripting Basics Related documentation 8
Articles and reference library
The Adobe XML Form Object Model Reference is a detailed reference of the models, objects, properties,
and methods that you can use with LiveCycle Designer. This PDF is intended as reference material only,
and is not intended to give users information on how to create calculations or scripts.
The LiveCycle Designer Forum is a meeting place for professionals who are interested in discussing issues
related to LiveCycle Designer. Respond to reader questions, report bugs or issues with the product, or post
questions of your own to other form designers and Adobe experts.
www.adobeforums.com
Scripting samples
The scripting samples are working forms or packages that include instructions on how the sample was
created, and include any sample data used to create and view the form. New samples are added on an
ongoing basis by both Adobe experts and third party organizations.
www.adobe.com/devnet/livecycle/samples.html
1
About Scripting in LiveCycle Designer
As part of the form design process, a form developer can use calculations and scripts to provide a richer
user experience. You can add calculations and scripts to most form fields and objects. For example, the
following JavaScript script multiplies the values of two numeric fields together and displays the result in a
third numeric field:
At a more advanced level, you can create your own functions tailored towards your own custom form
processing needs.
LiveCycle Designer supports two scripting languages, each geared towards the needs of a particular type
of form developer. FormCalc is a straightforward, easy-to-use calculation language that is modelled on
common spreadsheet functionality. It includes a variety of built-in functions designed to reduce the
amount of time you need to spend developing your form design. JavaScript, a powerful scripting
language, provides you with a great deal of flexibility when creating your scripts and allows you to
leverage any existing knowledge of the language.
Remember that scripting on a form is entirely optional. You can choose to take advantage of scripting to
provide a richer user experience, but many of the most powerful features available during form creation
are available in LiveCycle Designer without the use of scripts. However, through scripting, you can
manipulate and control almost all aspects of your form design.
How scripting works
LiveCycle Designer scripting uses an event-based model that allows you to alter various aspects of objects
on a form at run time. As a form designer, you add scripts to objects based on when you want the script to
execute. For example, you might place the following script on the
at run time, when a user clicks the button, a message box appears with a message:
xfa.host.messageBox("This is a message for a form filler.", "User Feedback", 3);
Scripts associated with a particular event execute whenever that event occurs. Some events can occur
multiple times within the same form filling session. For example, the following script adds one to the
current value of a numeric field:
If you add this script to the calculate event for NumericField1, when you open the form for the first
NumericField1 displays the value 2. This indicates that the calculate event occurred twice in
time,
the sequence of events that occurred when the form was opened.
click event of a button object so that
9
Adobe LiveCycle DesignerAbout Scripting in LiveCycle Designer
LiveCycle Designer Scripting Basics Objects that support calculations and scripts 10
Objects that support calculations and scripts
The following table provides a quick reference of scripting support for the standard objects that are
included in the Library palette in LiveCycle Designer.
Objects that support
calculations and scripts
BarcodesCircle
ButtonContent Area
Check BoxLine
Date/Time FieldRectangle
Decimal FieldImage
Document Signature FieldSubform Sets
Drop-Down ListTable sections
Email Submit ButtonText
HTTP Submit Button
Image Field
List Box
Numeric Field
Paper Forms Barcode
Objects that do not support
calculations and scripts
Password Field
Print Button
Radio Button
Reset Button
Subform
Table (including body rows,
header rows, and footer rows)
Text Fi el d
Configuring LiveCycle Designer Workspace for
2
Scripting
About the Script Editor
The Script Editor within LiveCycle Designer is where you create, modify, and view the calculations and
scripts of a particular form.
The Script Editor itself has both a single-line view and a multiline view, which you can easily switch
between, depending on your current needs. Single-line view is designed to maximize the amount of space
dedicated to the Layout Editor and other palettes, whereas multiline view is designed to maximize the
amount of space for writing script.
Single-line View
Multiline view
Script editing field
Show Events for Child
Object button
Show Lists all form design events that support user-defined scripting. Any events that do not apply to a
particular object appear dimmed. Events that contain a calculation or script display an asterisk (*) beside
the name of the event.
Show Events for Child Objects Displays the event you have currently selected in the Show list for
the current object and all of its child objects. If you select the uppermost object in the Hierarchy palette,
this option displays the event you have currently selected in the Show list for all objects on your form.
Functions Displays a list of available built-in FormCalc or JavaScript functions, depending on the
scripting language you currently have selected in the Language list.
To place a function onto your script editing field, select a function from the list and press Enter.
Enter Script Source Changes Saves your script to your form design. Click this button after you have
finished writing your script. If you do not save your script in this manner, it may not execute correctly or
may be lost.
Cancel Script Source Changes Undoes any changes you made to a particular calculation or script.
This button applies only to the current editing session and does not act as a multiple undo feature.
Functions button
Script editing fieldReference syntax
11
Adobe LiveCycle DesignerConfiguring LiveCycle Designer Workspace for Scripting
LiveCycle Designer Scripting Basics To show the Script Editor 12
Language Specifies the scripting language you want to use for the current calculation or script. Two
options are available:
● FormCalc is a native Adobe calculation language typically used for shorter scripts, such as simple
calculations.
● JavaScript is a robust and flexible scripting language suitable for more complex scripts.
Run At Specifies where the calculation or script will execute. Three options are available:
● Client Calculations and scripts execute while the client application (for example, Acrobat,
Adobe Reader, or a web browser) processes the form.
● Server ●Calculations and scripts execute while the server application (for example, LiveCycle Forms)
processes the form.
● Client and server ●Calculations and scripts execute while the server application (for example,
LiveCycle Forms) processes the form, except in cases where the HTML client application supports
client-side scripting. For example, a script that accesses a database to prefill data on a form.
To show the Script Editor
❖ Select Window > Script Editor.
Note: You can use the Expand button to quickly dock or undock the Script Editor when it is displayed in
the LiveCycle Designer workspace.
To change from single-line to multiline view
❖ Drag the Script Editor palette bar until the palette is the required size.
Note: Multiline view adds the All Events and Events with Scripts options to the Show list. The All Events
option displays all of the events for a particular form design object, even if the events do not
contain any calculations or scripts. The Events with Scripts option displays only those events of a
particular object that contain calculations or scripts.
To set the default scripting language
1. Select File > Form Properties.
2. Click the Defaults tab.
3. Select your default scripting language from the Default Language list.
Note: This procedure sets the value of the default scripting language only for the current instance of the
form.
To avoid changing the default scripting language each time you create a form, you must modify the
corresponding form template file that is used to create a new form design.
➤ To change the default scripting language for a form template
1. Create a new form design.
2. Select File > Form Properties.
Adobe LiveCycle DesignerConfiguring LiveCycle Designer Workspace for Scripting
LiveCycle Designer Scripting Basics To set the default processing application 13
3. Click the Defaults tab.
4. Select your default scripting language from the Default Language list.
5. Make a backup of the original form template file located in the Templates folder where
LiveCycle Designer is installed.
6. Save the new form design as a TDS file and overwrite the corresponding form template. For example,
save the file as Letter.tds and overwrite the Letter.tds file located in Templates\Blank folder.
To set the default processing application
1. Select File > Form Properties.
2. Click the Defaults tab.
3. Select your default processing application from the Default Run At list.
Note: This procedure only sets the value of the default processing application for the current instance of
the form.
To avoid changing the default processing application each time you create a form, you must modify the
corresponding form template file that is used to create a new form design.
➤ To change the default processing application for a form template
1. Create a new form design.
2. Select File > Form Properties.
3. Click the Defaults tab.
4. Select your default processing application from the Default Run At list.
5. Make a backup of the original form template file located in the Templates folder where
LiveCycle Designer is installed.
6. Save the new form design as a TDS file and overwrite the corresponding form template. For example,
save the file as Letter.tds and overwrite the Letter.tds file located in Templates\Blank folder.
To display Arabic, Hebrew, Thai, and Vietnamese characters
To display Arabic, Hebrew, Thai, and Vietnamese characters in the Script Editor or XML Source tab, you
must change the font settings that LiveCycle Designer uses in these tabs. Otherwise, LiveCycle Designer
displays rectangles where the language-specific characters should be.
Note: LiveCycle Forms 7.1 does not support form designs that contain Arabic, Hebrew, Thai, and
Vietnamese fonts.
1. Select Tools > Options and select Workspace from the list on the left.
2. Select one of the following options:
● FormCalc Syntax Formatting to set the font in the Script Editor when you use FormCalc
Adobe LiveCycle DesignerConfiguring LiveCycle Designer Workspace for Scripting
LiveCycle Designer Scripting Basics Using the workspace to debug calculations and scripts 14
● JavaScript Syntax Formatting to set the font in the Script Editor when you use JavaScript
● XML Source Syntax Formatting to set the font in the XML Source tab
3. In the Font box, select a font that supports your language. For example, Adobe Arabic supports Arabic,
Adobe Hebrew supports Hebrew, Adobe Thai supports Thai, and Myriad Pro and Minion Pro support
Vietnamese. You can locate the font you need for your language on the Internet if it is not already on
your system.
4. Click OK.
5. Click OK to close the Options dialog box.
Using the workspace to debug calculations and scripts
The LiveCycle Designer workspace provides a number of ways to assist you with debugging your
calculations and scripts.
The following table provides the location and purpose of some helpful debugging information located on
various LiveCycle Designer palettes and tabs.
Workspace locationPurpose
Warning tab in the Report
palette
The Warning tab is the first place form developers should check when
they encounter scripting errors or other unexpected form behavior.
The Warning tab acts as a log of issues reported by LiveCycle Designer
and updates when you preview your form design using the Preview
PDF tab.
Note: For run-time error checking in JavaScript, you should activate
the JavaScript Console. For more information, see “
To enable the
JavaScript Debugger for LiveCycle Designer” on page 68.
Bindings tab in the Report
palette
If you include fields on your form design that are bound to a data
source, the Binding tab can assist you by displaying lists of fields based
on how you defined their data binding. For example, you can list only
fields with Global Data Binding or only those with no data binding
defined. This feature is especially useful on forms that have a large
number of data bound fields.
Hierarchy paletteYou can use the Hierarchy palette to determine the location of a form
object for a reference syntax. The Hierarchy palette is a graphical
representation of the structure of a form. It displays the contents of the
Master Pages and Design View tabs.
The Hierarchy palette also displays referenced objects under the
Referenced Objects node. A referenced object is an object that is added
to a form only when it is required. Overflow leader and trailer subforms
are examples of referenced objects. Whenever data flows across
multiple pages or content areas, the overflow leader and trailer
subforms are inserted into the form in the appropriate places.
Adobe LiveCycle DesignerConfiguring LiveCycle Designer Workspace for Scripting
LiveCycle Designer Scripting Basics Using the workspace to debug calculations and scripts 15
Workspace locationPurpose
Binding tab in the Object
palette
Every LiveCycle Designer object that can be bound to a data source
includes a Binding tab in the Object palette. If you bind an object on
your form design to a particular data node from your data connection,
the Default Binding (Open, Save, Submit) list displays a valid FormCalc
reference syntax for accessing that data node. You can use the
FormCalc reference syntax in other calculations or scripts for testing
purposes.
XML Source tabThe XML Source tab contains the form design’s XML code. The XML
source code defines all aspects of the form. You can use the XML
Source tab to view the XML Form Object Model structure of a form
design and to understand the relationships between objects and
properties. In the XML source, the XML element names are equivalent
to the object names in the XML Form Object Model, and attributes are
equivalent to properties.
When you select an object in the Hierarchy palette and then click the
XML Source tab, the first line of the corresponding element is
highlighted. The object name in LiveCycle Designer, as listed in the
Hierarchy palette, becomes the value of the
name attribute in the XML
source.
You can set options in the Tools > Options dialog box for viewing the
source in the XML Source tab, such as showing or hiding line numbers
and setting the syntax coloring.
Caution: It is recommended that you do not edit the XML source code
directly.
You may also find it useful to change the default options for the Script Editor to make it easier to debug
your calculations and scripts. These options are in the Workspace panel of the Options dialog box, which is
available by selecting Tools > Options and then selecting Workspace from the list on the left. For example,
you can choose to display line numbers in the Script Editor or change the formatting of FormCalc or
JavaScript syntax.
3
Creating Calculations and Scripts
About creating calculations and scripts
LiveCycle Designer provides a wide range of calculation and scripting features that you can use to perform
a variety of tasks. For example, the following script changes the color of a text field border and the font size
of the text field value:
More complex forms can take advantage of scripting to perform data source connectivity and data
manipulation at run time. For examples of common scripting tasks, see “
Tasks” on page 91.
Creating calculations and scripts in LiveCycle Designer involves following a general process each time you
attach a calculation or script to an object. Although not all aspects of the process are required each time
you create a calculation or script, following the process helps to eliminate potential errors and unexpected
results.
In general, each time you create a calculation or script, you perform the following tasks:
● Select the object to which you want to attach a calculation or script. Although you can create
calculations and scripts that manipulate almost any object on your form design, not all form design
objects support form events. For a list of standard objects included in the Library palette in LiveCycle
Designer that support scripting, see “Objects that support calculations and scripts” on page 10
Examples of Common Scripting
.
● Select the form event to which you want to assign the calculation or script. The calculation or script
associated with an event executes each time the form event triggers. For example, calculations or
scripts attached to the
filling the form.
● Choose the scripting language you want to use. Depending on the form you create, you may decide to
use only FormCalc, only JavaScript, or a mixture of both languages. You can only use one scripting
language on a particular instance of a form object event.
● Choose where the calculation or script runs, either on the client application, such as Acrobat or
Adobe Reader, or on the server using LiveCycle Forms.
● Write your calculation or script in the script editing field of the Script Editor.
● Test the calculation or script either by using the Preview PDF tab or in your test environment.
click event of a button trigger each time the form filler clicks the button while
Naming conventions for form design objects and variables
When creating calculations or scripts to enhance your form, you should be aware of the form design object
and variable names on your form. In general, your form should avoid using the names of XML Form Object
Model properties, methods, and objects for form design objects and variables. Using XML Form Object
Model property, method, or object names can result in calculations and scripts not executing properly.
For example, if you create a new text field named
the text field object using the following syntax:
x within a subform object named Subform1, you access
Subform1.x.[expression]
16
Adobe LiveCycle DesignerCreating Calculations and Scripts
LiveCycle Designer Scripting Basics Choosing a scripting language 17
However, subform objects already have an XML Form Object Model property named x that represents the
horizontal position of the subform on the form design.
To avoid naming conflicts, you need to choose field naming conventions that differ from the XML Form
Object Model naming conventions. For example, you can use any of the following field names for the text
field in the example above:
● horizontalValue
● x_value
● xLetter
● hValue
For more information and a list of the XML Form Object Model property, method, and object names, see
the AdobeXML Form Object Model Reference at www.adobe.com/devnet/livecycle/designing_forms.html
.
Choosing a scripting language
LiveCycle Designer supports scripting with both FormCalc and JavaScript. Each scripting language
presents its advantages that you should be aware of before you write any scripts on your form.
FormCalc is a calculation language that includes a wide range of built-in functions to simplify the most
common form functionality. For example, you can use FormCalc financial functions to evaluate the size of
a loan payment based on the principle amount, interest rate, and number of payment periods.
JavaScript is a more powerful and diverse scripting language, intended to give you more flexibility and
leverage your existing scripting knowledge. For example, you can reuse your existing JavaScript functions
in LiveCycle Designer to reduce the amount of new scripting you need to create.
Note: LiveCycle Designer supports JavaScript version 1.6 or earlier.
The following table highlights some of the key differences between FormCalc and JavaScript.
FormCalcJavaScript
Native Adobe calculation language valid in
LiveCycle Designer and LiveCycle Forms
Standard scripting language used in many popular
software applications
Shorter scripts (typically one line only)Potential for longer scripts, if necessary, with the
ability to use looping
Contains a variety of useful built-in functions to
reduce the amount of scripting required to
Provides access to the Acrobat Object Model and
the JavaScript capabilities of Acrobat
accomplish common form design tasks
Support for international dates, times, currencies,
and number formats
Debugging possible by using the JavaScript
debugger in Acrobat
Built-in URL functions for
Post, Put, and Get
allow web-based interactions
Compatible on all LiveCycle Designer and
LiveCycle Forms supported platforms
Create custom functions for your own specific
needs
Compatible on all LiveCycle Designer and
LiveCycle Forms supported platforms
Adobe LiveCycle DesignerCreating Calculations and Scripts
LiveCycle Designer Scripting Basics To create a calculation or script 18
To create a calculation or script
1. Select an object on your form design that supports events. For example, add a button to a new, blank
form.
2. In the Script Editor, from the Show list, select one of the events that apply to the object. The event you
choose specifies when the script will execute. If you are writing a calculation or script that affects an
object that does not support events, you must add your calculation or script to a form design object
that does support form events. For example, using the new button object, select the
the Show list.
3. In the Language list, select your scripting language. For example, for the new button object, select
JavaScript.
4. In the Run At list, select where you want the script to execute. For example, for the new button object,
select Client.
You can choose to run calculations or scripts on your client-based application (for example Acrobat or a
web browser) or on your server-based process (for example, LiveCycle Forms). When set to Client,
processing of calculations and scripts initiates after the form renders. When set to Server, processing of
calculations and scripts initiates during the form rendering process. Previewing your form by using the
Preview PDF tab simulates opening the form in Acrobat; therefore, scripts set to run at Client or Client and
Server execute.
click event in
Note: Selecting Client And Server from the Run At list causes a script to execute in either the client
application or the server application, depending on which application is used to process the form.
5. In the Script Source field, insert your FormCalc calculation or JavaScript script. You can take advantage
of the statement completion functionality of LiveCycle Designer to help you create reference syntaxes
for your calculation or script. For example, add the following JavaScript script to the new button object:
xfa.host.messageBox("Hello World!", "Creating a new script", 3);
6. Click Enter Script Source Changes to add the script to your form.
7. After you complete your form design, test and debug your calculations and scripts before putting them
into production. For example, for the new button object, preview the PDF of the form using the
Preview PDF tab. Click the button object to display message box specified in step 5.
For more information about the LiveCycle Designer objects that support scripting, see “Objects that
support calculations and scripts” on page 10.
To find text or other items
You can quickly search for every occurrence of a specific word or phrase when you are in the XML Source
tab or in the Script Editor.
1. In the XML Source tab or the Script Editor, select Edit > Find or right-click for the context menu.
2. In the Find What box, enter the text that you want to search for.
3. Select any other options that you want.
4. Click Find Next.
Adobe LiveCycle DesignerCreating Calculations and Scripts
LiveCycle Designer Scripting Basics To replace text or other items 19
To cancel a search in progress, press Esc or select the Cancel button.
Caution: Although it is possible to edit XML source code directly in the XML Source tab, it is
recommended that you do not make any changes unless you are familiar with the Adobe XML
Forms Architecture. For more information about the XML Forms Architecture, see
www.adobe.com/devnet/livecycle/
.
To replace text or other items
You can automatically replace text. For example, you can replace Corp. with Corporation.
1. In the Script Editor, select Edit > Replace.
2. In the Find What box, enter the text that you want to search for.
3. In the Replace With box, enter the replacement text.
4. Select any other options that you want.
5. Click Find Next, Replace, or Replace All.
6. To cancel a search in progress, press Esc or select the Cancel button.
To replace text that appears in scripts attached to multiple objects on your form, select the root subform of
your form (by default:
procedure above.
Caution: Although it is possible to edit XML source code directly in the XML Source tab, it is
recommended that you do not make any changes unless you are familiar with the Adobe XML
Forms Architecture. For more information about the XML Forms Architecture, see
www.adobe.com/devnet/livecycle/
form1) and select Show Events for Child Objects and then perform the
.
To use statement completion to create calculations and scripts
The statement completion functionality within the Script Editor lets you build your calculations and scripts
interactively.
When writing a calculation or script, each time you enter a period (.) immediately following a form object
or property name, the statement completion functionality displays a list of available methods and
properties. If the statement completion list does not appear, verify that you have typed the object or
property name correctly and that the object is within the scope of the object where you are creating your
script. For more information about referencing objects in calculations and scripts, see “
Objects in Calculations and Scripts” on page 56.
Referencing
Adobe LiveCycle DesignerCreating Calculations and Scripts
1. Type the name of a form design object, property, or a valid FormCalc shortcut, followed by a period.
2. Select the method or property you want to apply for the form design object and continue writing the
script. To close the statement completion list without selecting a function, press the Esc key.
The list of available XML Form Object Model properties changes depending on the form design object or
property that appears before the period.
Note: The statement completion list appears only when accessing objects, properties, and methods in the
XML Form Object Model. It does not appear when working with standard JavaScript objects or
methods.
To insert object reference syntax automatically
As an alternative to using the statement completion list to create object reference syntax, you can use the
insert object reference syntax feature to automatically add reference syntax to your calculation or script.
This feature inputs an abbreviated reference syntax for the object you select from the canvas into the
Script Source field of the Script Editor. This reduces the time required to create calculations and scripts and
ensures that the reference syntax is accurate.
1. Ensure that the Script Source field of the Script Editor has the focus and the cursor is positioned where
you want to insert the object reference.
2. On your form, Ctrl+click the object you want to reference. The cursor changes to to assist you when
selecting an object.
Determining when to run your calculation or script
When creating calculations and scripts, you must associate each entry with a specific form event. Each
form event represents a change in the form’s state that initiates at a specific time. The change in form state
can occur during form rendering on the server by LiveCycle Forms, or on the client by Acrobat or
Adobe Reader while a user is filling a form. When a change in the state of the form occurs, any calculations
or scripts associated with the event are processed automatically.
The event you use when creating a calculation or script will, to some extent, determine what you must
include in your calculation or script. For example, the amount and type of information available on a form
may be different depending on the event timing you choose; therefore, a calculation or script that
Adobe LiveCycle DesignerCreating Calculations and Scripts
LiveCycle Designer Scripting Basics To view scripting events and scripts 21
retrieves a value from a field may have different results if run before instead of after a form filler performs
certain actions. For more information about events, see “
Events” on page 24.
Depending on the type of form you are creating, some events may never occur. For example, if you are
creating a form that has a fixed layout and no interactive objects, then interactive events associated with
form filler actions may never occur and, as a result, any scripts associated with those events will not run.
Although LiveCycle Designer includes support for a wide variety of form events, it is possible to
accomplish a wide variety of common calculation and scripting tasks by using only a few events that occur
at major changes in a form’s state, such as the following events:
● docReady ●Initiates immediately after the form opens in Acrobat or Adobe Reader® and immediately
before the form filler can begin interacting with form objects. This event is the last event to occur
before control of the form is given to the form filler.
● enter ●Initiates when the form filler changes the focus to a particular field, button, or subform.
● exit ●Initiates when the form filler changes the focus from a particular field, button, or subform, to
another object.
● change ●Initiates when a form filler makes a change to a field value. This event is most commonly
used with drop-down lists or list boxes to execute a script when a form filler makes a change to the
current value.
● click ●Initiates when a form filler clicks a field or button. This event is most commonly used with
buttons to execute a script when a form filler clicks the button.
To view scripting events and scripts
The Script Editor, provides several ways to view scripting events for objects in your form, depending on the
type of object or objects you select, and the quantity of events you want to display.
Before you begin, you must perform the following actions:
● If the Script Editor is not displayed on the screen, select Window > Script Editor.
● If the Script Editor is not large enough to display more than one line of script at a time, drag its lower
line down to increase its size.
➤ To view a scripting event for a single object in the Script Editor
1. Select an object in your form.
2. In the Show list, select a valid scripting event.
➤ To view a scripting event for a container object and its children in the Script Editor
1. If it is not already in multiline mode, expand the Script Editor to display multiple lines of script and
ensure that the Show Events for Child Objects option is selected.
2. Select a container object, such as a subform.
3. In the Show list, select a valid scripting event.
The events appear in the script editing field of the Script Editor, separated by the reference syntax for each
event. Note that certain events only apply to specific types of objects. When you select a script event, the
script editing field of the Script Editor only displays valid instances of the event. For example, if you select a
subform that contains a drop-down list and select the
preOpen event, the Script editor displays a single
Adobe LiveCycle DesignerCreating Calculations and Scripts
LiveCycle Designer Scripting Basics To view scripting events and scripts 22
entry representing the drop-down list. This is because the preOpen event only applies to drop-down lists.
Alternatively, selecting the
enter event displays two entries, one for the drop-down list and one for the
subform.
Note: The Show list denotes events that contain scripts using a trailing asterisk (*) after the name of the
event. If an event contains a script, when you select the event from the Show list, the source appears
in the script editing field of the Script Editor.
➤ To view all scripting events for a single object in the Script Editor
1. Select an object in your form.
2. In the Show list, select All Events.
The events appear in the script editing field of the Script Editor, separated by the reference syntax for each
event.
➤ To view all scripting events for a container object and its children in the Script Editor
1. If it is not already in multiline mode, expand the Script Editor to display multiple lines of script and
ensure the Show Events for Child Objects option is selected.
2. Select a container object, such as a subform.
3. In the Show list, select All Events.
The events appear in the script editing field of the Script Editor, separated by the reference syntax for each
event.
➤ To view all scripts for a single object in the Script Editor
1. Select an object that has scripts attached.
2. In the Show list, select Events With Scripts.
The scripts appear in the script editing field of the Script Editor, separated by the reference syntax for each
event.
➤ To view all scripts for a container object and its children in the Script Editor
1. If it is not already in multiline mode, expand the Script Editor to display multiple lines of script and
ensure that the Show Events for Child Objects option is selected.
2. Select a container object, such as a subform. All events for the container object and any child objects
appear in the Script Editor.
3. In the Show list, select All Events.
The scripts appear in the script editing field of the Script Editor, separated by the reference syntax for each
event.
Adobe LiveCycle DesignerCreating Calculations and Scripts
LiveCycle Designer Scripting Basics Determining where to run your calculation or script 23
Determining where to run your calculation or script
For each calculation and script created in LiveCycle Designer, you must specify the location where you
want the calculation or script to run.
Unless you are using server-based processing such as LiveCycle Forms, you should ensure that all of your
calculations and scripts are set to run on the client application (for example, on Acrobat or a web browser).
Note: FormCalc calculations and scripts do not work on forms rendered as HTML and are ignored during
form filling.
If you are using server-based processing, you can choose between running calculations on the client
application, or running them on the server. By choosing to have calculations and scripts run on the server,
you are choosing to run the scripts at a specific point during the form-rendering process.
If you choose Client And Server from the Run At list, your calculation or script is available to both client and
server-based applications. This option is useful, for example, if you do not know whether your users will
have client or server applications when they attempt to use your form. It is also useful if you want certain
form objects to behave one way to a client application and another to a server-based application.
Testing and debugging calculations and scripts
After you have created your calculation or script and tested your form, you may discover scripting errors or
other unexpected field values as a result of scripting errors.
LiveCycle Designer includes three primary methods for testing and debugging your calculations and
scripts:
● Using the LiveCycle Designer workspace palettes. For more information, see “Using the workspace to
debug calculations and scripts” on page 14.
● For JavaScript only, using the JavaScript Debugger to assist you in testing your scripts. For more
information on using the debugger, see “
page 68.
● Using the host model and event model properties and methods to troubleshoot your form.
The host model and event model provide functionality that lets you interact with either the host
application or the various form events. These models are useful for returning information that can assist
you in debugging calculation and scripts.
For example, the following script returns a message at run time indicating the name of the event on which
the script is placed. This indicates that a particular event has fired:
To enable the JavaScript Debugger for LiveCycle Designer” on
Another example of using the host model and event model methods is to obtain the value of a field on an
interactive form before a user manually changed it. This is useful for observing how the objects on your
form design respond to user-entered data:
Every calculation or script you attach to a form object is associated with a specific event. An event is
defined as a particular occurrence or action that can change the state of a form and, when the change of
state occurs, automatically invoke a calculation or script associated with the event. Events occur at various
times, from the beginning of the form rendering process when merging data with a form design, all the
way through to a form filler interacting with objects on a form in a client application. By applying
calculations and scripts to specific events, you can control every aspect of how you present form objects,
as well as form data, and how the objects and data respond to form filler interaction.
A single change of state or form filler action may trigger multiple events. For example, tabbing from the
current field to the next field triggers both the
the next field. If the current and next fields are in different subforms, a total of four events are triggered;
namely,
In general, each of the different categories of form events follow a predictable ordering.
exit events for the current field and subform, and enter events for the next field and subform.
Types of events
Form events fall into one of the following categories:
exit event for the current field and the enter event for
Process events This type of event initiates automatically as the result of an internal process or action
related to objects on a form. For example, if a form filler clicks a button that adds a new page to the form,
initialize, calculate, validate, and layout:ready process events initiate automatically for
the
the new page.
Interactive events This type of event initiates as a direct result of form filler actions. For example, if a form
filler moves the pointer over a field on a form, the
Application events This type of event initiates as a result of the actions that either a client application or
a server application performs. For example, you can create a calculation or script to perform a task
immediately after the form is saved by using the
Process events
Process events initiate automatically as the result of an internal process or action related to a form or
objects on a form. These events initiate immediately following significant form changes; for example, after
a form design is merged with data or after the form pagination process finishes. Process events also initiate
immediately after interactive events initiate. For example, immediately after any interactive event initiates,
calculate event initiates followed by the validate event.
the
The following list contains the process events, which are available from the Show list in the Script Editor:
● calculate
mouseEnter event initiates in response to the action.
Process events can initiate many times as a result of dependencies; that is, actions associated with a single
event that ultimately initiates one or more additional events. Using an example of a form filler clicking a
button to reveal a previously hidden portion of the form, after the form filler clicks the button, not only
does a series of interactive and processing events initiate for the button itself, but a number of process
events for the new subform initiates as well.
The following image represents the general flow of events leading up to a PDF form opening in Acrobat or
Adobe Reader.
After the form opens in Acrobat or Adobe Reader, these process events may still initiate as the result of
changes made to the form. For example, the
object initiate immediately after some interactive events occur; therefore, calculations and scripts
attached to the processing events will run multiple times.
Interactive events
Interactive events initiate as a direct result of form filler actions, which makes these events useful for a
variety of calculation and scripting tasks. For example, you can add a script to the
text field that changes the border color of the field to blue and a script to the
changes the border color back to the original color. This action creates a highlighting effect when form
fillers move the pointer over the field to visually assist them while filling the form. Interactive events are
also useful for changing form data in response to a form filler selection. For example, you can add a script
change event for a drop-down list that updates the data values in multiple fields in response to the
to the
value the form filler selects in the drop-down list.
calculate, validate, and layout:ready events for an
The following image displays the general flow of events for form fillers who use the keyboard to select an
object and change its value.
Application events
Application events initiate as a result of the actions that either a client application or a server application
performs, either in response to a form filler action or as a result of an automated process. For example, if a
form filler saves the form in Acrobat or Adobe Reader, the
save operation, followed by the
objects on the form. The same event sequence initiates if the form contains a script that programmatically
saves the form.
The following list contains the processing events, which are available from the Show list in the Script
Editor:
● docClose
● docReady
● postPrint
● postSave
● prePrint
● preSave
● preSubmit
Application events do not exist as part of a general flow of events. They are single events corresponding to
actions that the client or server application performs.
preSave event initiates immediately before the
calculate, validate, and layout:ready events, in order, for all
Adobe LiveCycle DesignerEvents
LiveCycle Designer Scripting Basics List of events 28
List of events
calculate event
Description
Initiates in the following situations:
● When your form design and data merge into your finished form.
● When a change occurs to any value that the calculation is dependent on, such as the value of a
particular field, unless the form filler has manually overridden the calculated value. As a result, the
object will display the return value of the event. The properties for manually overridden fields are
located in the Value tab of the Object palette.
● When a field loses focus; for example, when a form filler clicks or uses the Tab key to exit a field.
When using the
calculate event to perform calculations or scripts, consider the following potential
issues:
● Calculations and scripts on the calculate event must not make any changes to the structure of the
form, except for the form field and data values.
● Content inserted by the calculate event must conform to the associated validations for the object;
otherwise, validation errors will occur.
● Calculations and scripts must not include an infinite loop because it causes the form to update the
value continuously. For example, a script that increments the value of a field as part of a looping
expression, such as a
● The last expression evaluated in the calculate event is used to populate the value of the current
form object. For example, if the script on the
while or for loop, could create an infinite loop.
calculate event first sets the value of the current field
to 500 and then sets the value of another field to 1000, both fields will display the value 1000 at run
time. As a result, you need to limit the scripting that you add to the
calculate event to those that
deal specifically with setting the value of the current field.
Typ e
Processing event
Support
Client applicationAvailability
Acrobat and Adobe Reader
✔
HTML browser✔
Example
Use the calculate event for updating numeric values in fields because this event initiates immediately
after most other events. For example, on a purchase order form, you can use the
calculate event for a
field to determine the percentage of sales tax due based on the cost of the order. The calculation will
initiate every time a change is made to the values in the form fields, ensuring that the value displayed for
the sales tax is always correct.
However, because the
calculate event can initiate many times, you must ensure that the calculation or
script you add to the event will not cause data values to increment unnecessarily. For example, if your sales
Adobe LiveCycle DesignerEvents
LiveCycle Designer Scripting Basics List of events 29
tax calculation adds the value of the sales tax to the total cost each time the calculate event initiates,
the resulting total cost value on your form may be too large.
For a detailed example of using the
change event
Description
Initiates when a form filler changes the content of a field by performing one of these actions:
● Types a keystroke providing the field has keyboard focus
● Pastes data into the field
● Makes a selection from a list box or drop-down list
● Selects or deselects a check box
● Changes the setting of a group of radio buttons
This event does not initiate in response to changes in the object values as a result of calculations or scripts,
or by the merging of the form design with data.
Typ e
Interactive event
Support
Client applicationAvailability
calculate event, see “Calculating the field sums” on page 103.
Acrobat and Adobe Reader
HTML browser✔
Example
Use this event for any calculations or scripts that must initiate in response to a form filler changing the
value of a field. For example, you can use the
in a table. Using this technique, each time the form filler selects a value in the drop-down list, the
corresponding row of the table appears highlighted.
For a detailed example of using the
drop-down list” on page 100.
click event
Description
Initiates when a mouse click occurs within the region. When a click event initiates for a text or numeric
field, calculations or scripts execute immediately. However, the value of the field does not change in
response to calculations and scripts until the field loses focus.
✔
(Only for drop-down lists)
change event for a drop-down list to highlight specific rows
change event, see “Getting the current or previous value of a
Adobe LiveCycle DesignerEvents
LiveCycle Designer Scripting Basics List of events 30
Note: You cannot place a calculation or script on the click event of a submit button because the
calculation or script will override the submission action. Instead, place any calculations and scripts
on the
For more information about form submission actions, see the LiveCycle Designer Help.
preSubmit event for a submit button.
Typ e
Interactive event
Support
Client applicationAvailability
Acrobat and Adobe Reader
HTML browser✔
Example
Use this event for performing an action as a direct response to a form filler clicking a button or selecting a
radio button or check box on a form. For example, you can use the
and show a field on the form.
For a detailed example of using the
client” on page 97.
docClose event
Description
Initiates at the very end of processing a form, only if all form validations complete with no errors.
Typ e
Application event
Support
Client applicationAvailability
✔
click event for a check box to hide
click event, see “Changing the visual properties of an object on the
Acrobat and Adobe Reader
HTML browser✘
✔
Example
This event initiates too late to modify a saved form and is intended to provide the ability to generate an
exit status or completion message. For example, you can use the
a form filler indicating that the form is completed.
docClose event to display a message to
Loading...
+ 89 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.