A comment starts with a semicolon (;) or two slashes (//). It ends with the next line of coding.
Commands may stretch over several lines.
FormCalc has approximately 40 keywords (for example, if, do, and or). They are case-insensitive.
FormCalc has the usual calculation operators (+, -, *, and /) and comparison operators (==, <>, <, >, <=, and >=). You can also use English short forms for the comparison operators (eq, ne, lt, gt, le, and ge). Programmers who are used to ABAP should take care not to confuse the assignment operator (=) with the equals operator (= =).
Variables are case-sensitive.
Elements from the form that you can use as fields in the coding are called accessors. An accessor allows you to query or change a field value or an object property.
To access a field value from the form context (Data View), prefix the name with $record. Give all parts of the name as it appears in the Data View, separated by a period. The original ABAP representation is irrelevant.
Accessing Context Field Values
You can access all context fields in the Data View, even those you have not included in your layout.
When accessing a field of an internal table, note the following:
- Take care to follow the path shown in the Data View. Due to the XML representation of internal tables, there is always a layer called DATA between the internal table and its fields.
- If you do not specify which dataset you want to access, the first one will be shown (there is also a more general form of this rule – if two objects at the same hierarchy level happen to have the same name, any unspecific reference to them is actually considered a reference to the first object of that name).
- If you want to access a specific dataset of an internal table, include the number of that dataset in square brackets. For example, $record.IT_SUMS.DATA[4].CURRENCY. Note that unlike sy-tabix in ABAP, the first line is number 0, the second line is number 1, and so on.
- If you want to access all datasets of the internal table, include an asterisk in square brackets. For example, $record.IT_SUMS.DATA[*].CURRENCY.
You can also access a field value by giving its name as shown in the Hierarchy palette. You need this for all fields with no data binding, that is, for all fields that do not come from the Data View. Furthermore, you must use this method if you want to change object properties at runtime.
Accessing Fields from the Hierarchy
Use $ to access the current object.
You can access objects by giving just their names, as follows:
- At the same hierarchy level
- At the level of one of its enclosing subforms
- Direct children (if the object to which scripting is attached is a subform)
In the example, within scripting for subform SUB1, you can access the objects SUB2 and MAIL by giving their names.
An easy test to determine whether an object is accessible through its name is to type the name in Adobe LiveCycle Designer Script Editor, followed by a period. If an input help appears, the object is accessible directly.
You can access children anywhere along a subform’s hierarchy. To do so, specify the traversed subforms or summarize them with two periods. For example, starting from SUB1, you could access PHONE with $. .PHONE.
You can access all fields by giving their fully qualified paths and names. Start with the name of the master page or the corresponding page (design view), and insert all hierarchy levels on the way down to the object. If the hierarchy path contains unnamed subforms, you should leave these out. An easy way of getting to the name of an object is to position the cursor on the object in the hierarchy, choose the Script Editor, and display one random event. The first line is always a comment, such as data.Masters.FIRST.SUB1.SUB2.NAME: : ready: layout. The name of the element precedes the double colon. In this case, it would be data.Masters.FIRST.SUB1.SUB2.NAME.
Specify the minimal definition of the field for performance reasons.
Value Assignment
Here are some examples of value assignment:
123456789101112
;event initialize of text field PHONE_NO
if ($record.IS_CUSTOMER.COUNTRY == "US")
then $ = "+49 6227 888888"
else $ = "+49 6227 777777"
endif
;event calculate of text field PHONE_NO
if ($record.IS_CUSTOMER.COUNTRY == "US")
then "+49 6227 888888"
else "+49 6227 777777"
endif
In the calculate event, no assignment of the ordinary kind (for example, $ = a) is required if you want to set the value for the field for which the coding is written. Instead, the field takes the value of the last expression. In the example, the text field PHONE_NO has the value +49 6227 888888 if the IS_CUSTOMER.COUNTRY field equals US; otherwise, it is +49 6227 777777.
For a value assignment in events other than CALCULATE, an ordinary assignment, such as $ = a is required.
Variables
For your scripting, you can also define variables within the form without changing the form interface or context. You can do this in the form properties on the Variables tab page. These variables are globally known within the form. They also appear in the Hierarchy, but they cannot be integrated in the form like ordinary text fields from the context, nor can they be used for the Default Binding.
Variables can be text variables (with several lines) or numbers. Variable names are not case-sensitive. You can also use scripting to change object properties.
Some examples of changing object properties are as follows:
12345678910
FOOTER.presence = "hidden"
StaticImage1.rotate = "90"
StaticText1.x = "12cm"
StaticText1.caption.font.fill.color.value = "200,0,0" ;RGB values
TextField1.caption.value.text = "Dynamic caption"
TextField1.assist.toolTip = "Better explanation"
$.break.after = "contentArea" ;page break after current subform
;can be processed only for subforms
To access the properties of a static object, you must attach the relevant scripting to a non-static object, because static objects do not have events and, therefore, they have no scripting.
If the values you want to set contain units, for example, 12cm, you must enclose the values in quotation marks.
Hiding a subform hides all of its content as well.
Some properties include RGB values, which are combinations of three digits between 0 and 255 that specify how strong the red, green, or blue parts of the form should be.
For example, 0, 0, 0 represents black; 255, 0, 0 red; and 255, 255, 255 represents white.
For details, check the object reference in Adobe LiveCycle Designer online help. To find a suitable scripting command, you might find it helpful to create a dummy object that has the desired settings, and look at the XML representation.
For example, the caption of a text field called TextField1 would look like this:
1234567
<caption reserve="35mm">
<font typeface="Arial" size="12pt"/>
<para vAlign="middle"/>
<value>
<text>Here is the caption</text>
</value>
</caption>
You can dynamically assign a caption as:
1
TextField1.caption.value.text = "Dynamic caption"
To change the caption’s font dynamically, write:
1
TextField1.caption.font.typeface = "Times New Roman"