Creating MetaScript for Dynamic Popups

Creating MetaScript for Dynamic Popups

The Popup Field Tool allows you to create popup lists with items that are calculated dynamically as a result of a script. A dynamic popup should be used when, for example, you are specifying employees responsible for a particular task: instead of entering a long list of employee names, you may have the contents of the popup be determined by a script that queries the Job Manager database when the form is opened. Because the value of the popup can be referenced in the MetaScript of other form objects, dynamic popups may also be configured to allow the user to dynamically control the contents of an entire form.

To create MetaScript for dynamic popups:

1. Select the Popup Field Tool from the Tools Palette and go through the steps as described in "Creating Popups" until you reach the point where you define the popup contents.

2. Select MetaScript from the "Popup is filled by:" drop down menu in the popup Control Palette. This will change the popup from one that displays a static list of values to one that calculates the popup list dynamically.

3. Click the MetaScript button in the Script field. Type the MetaScript code that will be executed beneath the field/variable on the form in the Popup Script window. You may also define the MetaScript code in the Script field without using the Popup Script window.

Scripts may include function definitions which may be called from other scripts within the form. For details on functions and commands supported by MetaScript, please refer to the MetaScript Reference manual.

note: The MetaScript code you type determines the contents of the dynamic popup list in the following manner:

4.. If the result of the MetaScript calculation is NULL, the contents of the dynamic popup list remain unchanged.

5. If the result of the MetaScript calculation is an instance of the Array type, the popup will be populated with the array items, in the same order as they appear in the array. For each array item, the value and the displayed text will be determined as follows:

- If the item is an object and the item has a "value" property,
The value of the corresponding popup item is set to the string
representation of item.value, and
- If the item also has a "text" property,
The text of the corresponding popup item is set to the string
representation of item*.*text.
- If the item does not have a "text" property
The text of the popup item is set to the string representation of
item*.*value
- If the item is not an object or the item does not have a "value" property*,**
*
Both the value and the text of the corresponding popup item are set
to the string representation of the item itself*.**
*
6. If the result of the MetaScript calculation is not an instance of the Array type, the popup list will be populated using the properties of the calculation result in an arbitrary order. For each property:

- The value of the corresponding popup item is set to the property name, and
- The text of the corresponding popup item is set to the string representation
of the property.


7. If the text of a popup list item begins with "-", that item will be displayed as a separator. If the text of the database field or variable underlying the popup begins with "-", the popup will be grayed and italicized on the form.

8. Close the script editor window by clicking the close window box in the upper left hand corner or press Command-W.* Apply the appropriate attributes (style, size, font, color) to the new popup.

9. Select Save Form from the Form menu to save the changes you have made to the form.


Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.