{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":39800,"path":"platform-administration/t_EditingAUIAction.md","title":"Create a UI action","bundle":null,"doc_type":null,"release":"australia","body":"\n# Create a UI action\n\nYou can create a new UI action or edit an existing one.\n\n## Before you begin\n\nRole required: ui\\_action\\_admin or admin\n\n## About this task\n\nYou can add UI actions to tables and database views that are in the same scope as the UI action and tables that allow UI actions from another application scope to run on them.\n\n## Procedure\n\n1.  Navigate to **All** &gt; **System Definition** &gt; **UI Actions**.\n\n2.  Click **New** or open an existing record.\n\n3.  Define the UI action by completing the fields.\n\n    You may need to configure the form to see all the fields.\n\n<table id=\"table_epb_5pl_hp\"><thead><tr><th>\n\nField\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nName\n\n</td><td>\n\nThe text that appears on the button, link, or context menu item.**Note:** If the Action name and Name fields are both exactly the same in two different UI actions, they will be de-duplicated at runtime to prevent users from seeing two of the same actions.\n\n</td></tr><tr><td>\n\nTable\n\n</td><td>\n\nThe table on which the UI action is available. By default, the UI action also appears on tables that extend the selected table \\(for example, Task actions appear on the Incident table\\). Select **Global** to make the action available on all tables.\n\n</td></tr><tr><td>\n\nOrder\n\n</td><td>\n\nThe order in which the UI action appears. The order applies to buttons from left to right and to menu actions from top to bottom.\n\n</td></tr><tr><td>\n\nAction name\n\n</td><td>\n\nA unique name to use when referencing the UI action in scripts.**Note:** If the Action name and Name fields are both exactly the same in two different UI actions, they will be de-duplicated at runtime to prevent users from seeing two of the same actions.\n\n</td></tr><tr><td>\n\nActive\n\n</td><td>\n\nAn option to enable the UI action when selected. To disable a UI action, clear the check box.\n\n</td></tr><tr><td>\n\nShow insert\n\n</td><td>\n\nAn option to show a button on new records that have not been inserted.\n\n</td></tr><tr><td>\n\nShow update\n\n</td><td>\n\nAn option to show a button on existing records.\n\n</td></tr><tr><td>\n\nClient\n\n</td><td>\n\nAn option for the UI action to execute its script in the user's browser, not on the server. When enabled, the **Onclick** field appears above the Condition field.\n\n</td></tr><tr><td>\n\nForm button\n\n</td><td>\n\nAn option to put a button on a form.\n\n</td></tr><tr><td>\n\nForm context menu\n\n</td><td>\n\nAn option to put an item in a form context menu \\(right-click the form header\\).\n\n</td></tr><tr><td>\n\nForm link\n\n</td><td>\n\nAn option to put a link in the Related Links section of a form.\n\n</td></tr><tr><td>\n\nForm style\n\n</td><td>\n\n-   Primary—Colors the UI Action blue.\n-   Destructive—Colors the UI Action red.\n-   Unstyled—Does not color the UI Action.\n\n\n</td></tr><tr><td>\n\nList banner button\n\n</td><td>\n\nAn option to put a button in the banner of a list.**Note:** List banner buttons are not intended to support record-specific conditions, so only the first row is considered when the condition is evaluated to determine whether the button will show for the list. Do not use record-specific conditions \\(e.g., current.getValue\\('state'\\) === 'closed'\\) in list banner button UI Actions.\n\n</td></tr><tr><td>\n\nList bottom button\n\n</td><td>\n\nAn option to put a button at the bottom of a list.**Note:** List bottom buttons show regardless of condition and are evaluated per record on execution.\n\n</td></tr><tr><td>\n\nList context menu\n\n</td><td>\n\nAn option to put an item in a list field context menu \\(right-click a cell in a list\\).\n\n</td></tr><tr><td>\n\nList choice\n\n</td><td>\n\nAn option to put an item in the action choice list at the bottom of a list.**Note:** List bottom buttons, like list choice actions, show regardless of condition and are evaluated per record on execution.\n\n</td></tr><tr><td>\n\nList link\n\n</td><td>\n\nAn option to put a link in the Related Links section at the bottom of a list.\n\n</td></tr><tr><td>\n\nList style\n\n</td><td>\n\n-   Primary—Colors the UI Action blue.\n-   Destructive—Colors the UI Action red.\n-   Unstyled—Does not color the UI Action.\n\n\n</td></tr><tr><td>\n\nOverrides\n\n</td><td>\n\nA UI action that this UI action overrides.\n\n</td></tr><tr><td>\n\nMessages\n\n</td><td>\n\nText strings that the UI action can use as a key to look up a localized message alternative from the Message \\[sys\\_ui\\_message\\] table. Each message key is on a separate line in the Messages field. The instance looks for a localized message string anytime the UI action makes a getMessage\\(msg\\) call where the msg string matches a key in the Messages field.\n\n</td></tr><tr><td>\n\nComments\n\n</td><td>\n\nDescriptive content regarding this UI action.\n\n</td></tr><tr><td>\n\nHint\n\n</td><td>\n\nThe text that appears when a user points to the UI action control.\n\n</td></tr><tr><td>\n\nOnclick\n\n</td><td>\n\nThe name of the JavaScript function to run when the UI action is executed. The function is defined in the **Script** field.\n\n</td></tr><tr><td>\n\nCondition\n\n</td><td>\n\nA JavaScript conditional statement that restricts when a UI action appears. Conditions always run on the server.**Note:**\n\n-   The current object is not available for conditions on a list context menu. If the **List context menu** option is selected, any use of **current** on these actions is ignored.\n-   You can reference the parent record for the UI action conditions on a related list button. For example, to disable the **New** and **Edit** buttons on the Affected CIs related list for closed changes, copy the global m2m UI actions to the task\\_ci table and add a condition of **parent.active**.\n-   If you leave one of the fields empty that you specify in your condition statement, that condition defaults to **true**.\n\n\n</td></tr><tr><td>\n\nScript\n\n</td><td>\n\nThe script to run when the UI action is executed. Function names must be unique.\n\n</td></tr><tr><td colspan=\"2\">\n\nWorkspace\n\n</td></tr><tr><td>\n\nWorkspace Form Button\n\n</td><td>\n\nAn option to make the UI action appear on the list of UI actions in a workspace.\n\n</td></tr><tr><td>\n\nWorkspace Form Menu\n\n</td><td>\n\nAn option to make the UI action appear as a list item in the menu associated with UI actions in a workspace.\n\n</td></tr><tr><td>\n\nFormat for Configurable Workspace\n\n</td><td>\n\nAn option to use the UI action in a Configurable Workspace. If cleared, the UI action applies in Legacy Workspaces.\n\n</td></tr><tr><td>\n\nWorkspace Client Script\n\n</td><td>\n\nA script to run when the UI action is executed in workspaces.\n\n</td></tr><tr><td colspan=\"2\">\n\nRequires role\n\n</td></tr><tr><td>\n\nRole\n\n</td><td>\n\nThe roles required for the UI action to apply. Users must have at least one of the roles for the UI action to apply.\n\n</td></tr><tr><td colspan=\"2\">\n\nRelated lists on the form view\n\n</td></tr><tr><td>\n\nUI Action Visibility\n\n</td><td>\n\nThe views of the form that the UI action applies to. Use this option to restrict the UI action to form views that you specify. A UI action is available for the specified view according to the following rules:1.  If there are no visibility rules, the action appears on all views.\n2.  Any exclude rule on a given view means that the action does not appear on that view.\n3.  If there is at least one include rule, then the action appears only on views that are specifically included.\n\n\n</td></tr><tr><td>\n\nVersions\n\n</td><td>\n\nAll versions of the UI action. Use this list to compare versions or to revert to a previous version.\n\n</td></tr></tbody>\n</table>4.  Click **Submit** or **Update**.\n\n    **Note:** If the UI action is enabled to run on the client side, wrap it in a function. Otherwise, the contents of the **Script** field runs when the page loads.\n\n\n## Example\n\nAs part of a UI action script, you can redirect a user to a URL. For example, you might add links to a form or open a new record after it is created from a UI action. To redirect a user to a URL from a UI action, use this syntax in the **Script** field to define the redirect link:\n\n```javascript\naction.setRedirectURL ( '[http://www.mysite.com/mypage.htm](http://www.mysite.com/mypage.htm)' );\n```\n\nTo direct a user to a record, use this syntax, where **new\\_record** is the variable name for the [GlideRecord](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/server-api-reference/c_GlideRecordScopedAPI.md):\n\n```javascript\naction.setRedirectURL (new_record );\n```\n\n**Parent Topic:**[Defining UI actions](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/platform-administration/c_UIActions.md)\n\n"}}