Making and Reusing Static Lists in a Stored File for Use in Forms
Use a MetaScript array in a Stored File to create static lists in multiple forms.
Details
By using a MetaScript array in a Stored File, a list of items can be created and maintained once and used in Popups across multiple forms in a Virtual Ticket or Digital Storage Manager system. Such a script can save time in much the same way that dynamic popups save time: by reducing the need to manually enter values across multiple popup fields.
Note: Static lists created in a Stored File can be used in any form in the system. To create a static list that can be used only within a particular form, see Toolbox Snippet - Making Static Lists in Global MetaScript for Use in a Form.
Example
This example describes how to create a static list in a stored file and use it in a Popup field on any form in your Virtual Ticket or Digital Storage Manager system. To achieve this, perform the following steps:
- Open a text editor and copy and paste the following text into it:
function getList() { var mylist = new Array("KGAN", "KCRG", "KFXT", "KCIC", "CNN1", "CNN2", "Weather Chan", "Discovery", "History", "Comedy Central", "USA"); return mylist.sort(); }
- Save the file with a .js extension. For this example, we've named the file "TS559_channelnames.js".
- Select the Stored Files menu item from the Administration menu. The Stored Files window will open.
- Click the New->Stored Script(s) button and add the .js file created in Steps 1-2 above to the database as a stored script file.
- For each form which will use the stored script, open the Global MetaScript editor and enter the following text:
//@include "database:TS_559_ChannelNames.js" - This statement tells the application to use scripts from the TS_559_ChannelNames.js file added to the database.
- Create a Popup Field on the form and assign a database field to it using the "Field" selector in the Control Properties panel.
- Make the field Editable by selecting "Yes" for the "Editable" value in the Control Properties panel.
- Select "MetaScript" in the "Popup is filled by" control in the Control Properties panel.
- Type "getList();" in the "List MetaScript" control in the Control Properties panel.
- Save the form.
- Result: The Popup Field in the form will contain the static list contained in the .js file added to the database. By defining the getList() function in the stored script file added to the database, the static list in the .js file can be used in any form in the database.
Resources
- Download and install a sample form and sample .js file illustrating this Toolbox Snippet (see below)
- Knowledge Base Article 16020 - MetaScript Example - Making and Reusing Static Lists
- Toolbox Snippet - Making Static Lists in Global MetaScript for Use in a Form
- Toolbox Snippet - Sorting a Static List with MetaScript