onShow script for list context menus
The onShow script field defines a script that runs before the context menu is displayed to determine which options appear in the context menu.
Use this script to change the menu items on the list header menu based on the current field
column. The following JavaScript variables are available to the onShow
script when it is executed:
| Variable | Description |
|---|---|
| g_menu | Context menu to be displayed. |
| g_item | Current context menu item. |
| g_list | GlideList2 against which the script runs. |
| g_fieldName | Name of the field against which the context menu runs. |
| g_fieldLabel | Label of the field against which the context menu runs. |
| g_sysId | The sys_id of the row or form against which the script runs. |
An example of an onShow script is one that determines when to enable or
disable the Ungroup option in a list column heading menu based on
whether the list is grouped or
not.
if (g_list.getGroupBy()) {
// list is grouped so enable to Ungroup menu item
g_menu.setEnabled(g_item);
} else {
// list is not grouped, so disable the Ungroup menu item
g_menu.setDisabled(g_item);
}