onShow script

The onShow script contains a script that runs before the menu is displayed that determines the items to be present based on current information about the menu being displayed.

The onShow script is typically used 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:
Table 1. onShow script variables
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 header menu based on whether the list is currently 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);
}