Please use docs.servicenow.com for the latest documentation.

This site is for reference purposes only and may not be accurate for the latest ServiceNow version

Context Menus

From Wiki Archive
Jump to: navigation, search


Note
Note: The latest release that this documentation applies to is Fuji. For documentation on the Geneva release, see Context menus.

Documentation for later releases is also on docs.servicenow.com.


Overview

Context menus in ServiceNow lists are right-click menus that provide three different levels of controls, depending on the view from which they are opened. The content and behavior of context menus can be controlled by an administrator using procedures described on this page.

Context Menu Views

The following context menus are configured for administrative users in the out-of-box system. The menu options discussed here are for commonly used tables, such as Incident and Change. Other options not discussed here might appear on menus for other tables. Menu options presented to users can be controlled with roles.

List Title

Click the arrow in the title of the list to access options related to viewing and filtering the entire list.


Context_Menu_List_Title.png‎


Option Description
View Changes the view of the list by presenting different information.
Filters Changes the values in the filter. Some of the choices are: None, Active, and Edit personal filters.
Group by Groups records in a list by the values in a selected field from that table. Any field from the table can be used as a group filter, whether or not it appears in the list.
Show Changes the number of rows shown on each page of the list.
Refresh List Refreshes the list to show changes immediately.

List Header

Right-click in the header row of a column to display actions related to that column.


Context_Menu_List_Header.png‎


Option Description
Sort (a to z)/(z to a) Sort the selected column in ascending or descending order.
Group by <column> Group records by the values in the selected column and arrange the groups alphabetically.
Charts Create Bar or Pie charts on the fly for the values in the selected column.
Configure (Personalize prior to Fuji) Configure the list for all users on this instance. This includes the layout, calculations, and controls. Use these controls to access other features such as UI Actions, UI Policies, and the Dictionary.
Export Export all the records in the list using the selected file format.
Update Separate/All Perform updates to a single record or to multiple records at once using the appropriate form for that table. See Editing Multiple Records for instructions. This option requires the list_updater role.
Import XML Import records into this table from an external XML file.

List row

Right-click in a row to see a menu with actions related to the values in that row.


Context_Menu_List_Row.png‎


Option Description
Show Matching Displays only those records containing values that match the cell selected.
Filter Out Filters out records containing values that match the cell selected.
Copy URL to Clipboard Copies the URL for the selected record to the clipboard.
Copy sys_id Copies the sys_id (unique record identifier) of the record selected to the clipboard.
Assign Label Create new labels or select existing labels for a section at the top of the left navigation pane that organizes related records. Right-click on a record and select a label to add that record to the section. Remove records from a label by clicking on the X.
Approve Approves the request in the selected record(s). This option is only available for tables in which records are subject to approvals.
Assign to me Assigns the selected record to the current user. This option is only available for tables in which records can be assigned.
Reject Rejects the request in the selected record(s). This option is only available for tables in which records are subject to approvals.

Creating a Context Menu

To create a context menu, navigate to System UI > UI Context Menus, and then click New in the list of menus. The Context Menu form provides the following fields:


Field Description
Table Select the table to which this context menu option is attached. The base system menu items are attached to the Global [global] table, which applies the context menu option to all lists for all tables. If you specify a particular table, the option is available only on context menus in lists from that table.


Note
Note: The list shows only tables and database views that are in the same scope as the context menu (starting with the Fuji release).
Menu Select the menu in which this option appears. See the sample lists on this page.
  • List title
  • List header
  • List row
Type Select the type of menu option to create:
  • Action: A menu option that performs an immediate action.
  • Menu: Creates a parent menu that can display a submenu
  • Separator: Draws a line between groups of options on a menu. The menus will not display separator lines adjacent to one another or at the bottom of a menu. If a condition that removes options for a role forces two separators together, one of the separators is removed from the view.
  • Label: Create an unlinked label for a menu or section of a menu.
  • Dynamic actions: Menu options dynamically created, such as the available views or user filters that can only be generated at the time the list is displayed.
Name Type the label for the action as it will appear in the menu.
Parent If this action is part of a submenu, type the name of the parent menu item. For example, in the base system, Configure (Personalize in versions prior to Fuji) is a parent.
Order Assign this item, menu, or separator an order number to determine where in the menu it appears.
Active Enable or disable this context menu item. Only active items are shown in the context menu.
Condition Create the conditions under which this menu option appears. For example, define the role that has permission to see this item.
Run onShow script Select this check box to display the onShow script field.
Action script The action script is the code that runs in response to the menu item that is selected.
Dynamic actions script The dynamic actions script builds the dynamic items that appear on the menu, such as filters or views.
onShow script The onShow script contains a script that runs before the menu is displayed that determines the items to present based on previous settings.


A menu item for a dynamic action looks like this.


Context_Menu_Form.png‎

Available Variables

Use these variables to create scripts for context menus.

Action Script

The action script is the code that runs in response to the menu item being selected. This is a client-side script that runs in the user's browser. The following javascript variables are available to the Action script when it is executed:

Variable Description
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.


The out-of-box system uses the following in an action script to refresh the platform view:

<source lang="javascript">g_list.refresh(1);</source>

Another example is the use of these variables in a list header menu to sort a list by the selected field in descending order (z to a).

<source lang="javascript">g_list.sortDescending(g_fieldName);</source>

Dynamic Actions Script

The dynamic actions script builds the dynamic items that appear on the menu, such as filters or views. The following JavaScript variables are available to the dynamic actions script when it is executed.

Variable Description
g_tableName Name of the current table.
g_listId ID of the list for which the context menu is built.
g_itemName Name defined in the UI context menu record.
g_itemOrder Order defined in the UI context menu record. Use this variable to pass the value of the Order field to the dynamic actions script.
g_contextMenu.addAction(item_id, label, script_string, order) Add options to the context menu and select the order in which they appear.

The following example displays a list title menu item that controls the number of records per page in the list view:

<source lang="javascript">g_contextMenu.addAction('50', g_itemName, 'showRowsPerPage("50");', g_itemOrder);</source>

Note
Note: The Action Script for this item must define the showRowsPerPage function so that when selecting this menu item, that function is called with an argument of 50.


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:

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.

<source lang="javascript">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);

} </source>