My collected list of useful UI Actions
**If you want to get notified when new UI Actions are added by me, you can subscribe to this page!**
Over time, every developer or system administrator builds little helpers that make working with ServiceNow more convenient and secure. This is also true for me, and in this article I present a few UI Actions that have been collecting in my toolbox.
## What are UI Actions?
UI Actions are custom actions users can perform on records in the ServiceNow interface. They are typically associated with forms and lists and appear as buttons or context menu options. UI Actions allow users to initiate specific actions, such as creating records, updating fields, running scripts, or navigating to related pages, directly from the ServiceNow interface. They can be configured to execute client-side or server-side scripts to perform desired operations. UI Actions help users work faster and more efficiently by giving them quick access to common ServiceNow functions.
Please refer to the [ServiceNow documentation pages](https://docs.servicenow.com/csh?topicname=c%5FUIActions.html&version=latest) for more information about UI Actions.
## Open Scan Finding related Record in List View
In most of the cases, a finding record of an Instance Scan (table **scan\_finding**) will reference the identified source record, and you can open that source record as usual. The problem here are source records from the **sys\_attachment** table. These cannot be opened in the form view. Instead, ServiceNow starts a download of the underlying file. However, this takes away the possibility of examining the **sys\_attachment** record in more detail in order to understand the cause of the finding.
Therefore, the following UI Action (related link in form view and context option in list view) will open the referenced record in the list view, thus allowing to add the required columns for more information.
### UI Action
| **Table** | **scan\_finding** |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Form link** | true |
| **List Context Menu** | true |
| **Client** | true |
| **Onclick** | openSourceRecordInListView() |
| **Condition** | gs.hasRole('scan\_user') |
| **Script** | function openSourceRecordInListView() { var \_grScanFinding = new GlideRecord('scan\_finding'); \_grScanFinding.addQuery('sys\_id', rowSysId \|| g\_form.getUniqueValue()); \_grScanFinding.query(); if (\_grScanFinding.next()) { var \_strSourceTableName = \_grScanFinding.source\_table.toString(); var \_strSourceRecordSysID = \_grScanFinding.source.toString(); g\_navigation.openPopup( '/' + \_strSourceTableName + '\_list.do?sysparm\_query=sys\_id=' + \_strSourceRecordSysID ); } } |
## Open Attachment-related Record from List View
Basically, an attachment record at table sys\_attachment is associated with a related record. For example, an Excel file attached to a data source. That relationship is designed as a Document ID reference at table sys\_attachment. And because of records in the sys\_attachment table do not have a form view, it is impossible to open the referenced record from the list view. Instead, you have to open the related target table manually and lookup the target record via its Sys ID which is a pretty bad user experience. Therefore, I built a list action for the context menu, allowing me to open the target record with a mouse click.
### UI Action
| **Table** | **sys\_attachment** |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **List Context Menu** | true |
| **Client** | true |
| **Onclick** | openRelatedRecord() |
| **Condition** | !current.table\_name.nil() && !current.table\_sys\_id.nil() && !current.table\_name.startsWith('invisible.') && current.table\_name != 'sys\_attachment' |
| **Script** | function openRelatedRecord() { var \_grRecord = new GlideRecord('sys\_attachment'); \_grRecord.addQuery('sys\_id', rowSysId); \_grRecord.query(); if (\_grRecord.next()) { var \_strTableName = \_grRecord.table\_name.toString(); var \_strRecordSysID = \_grRecord.table\_sys\_id.toString(); if (\_strTableName.startsWith('ZZ\_YY')) { \_strTableName = \_strTableName.substring(5); } g\_navigation.openPopup('/' + \_strTableName + '.do?sys\_id=' + \_strRecordSysID); } } |
## Open Metadata Snapshot-related Records
In ServiceNow, we can add pure data records to an application via [action "Create Application Files"](https://docs.servicenow.com/csh?topicname=t%5FIncludeApplicationData.html&version=latest). These records are stored at table **sys\_metadata\_link** and thus associated to a certain application.
However, just as with the **sys\_attachment** table, ServiceNow has forgotten to provide a UI Action that allows the original data record to be opened directly in the form as well as list view.
### UI Action
| **Table** | **sys\_metadata\_link** |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Form link** | true |
| **List Context Menu** | true |
| **Client** | true |
| **Onclick** | openRelatedRecord() |
| **Condition** | new GlideRecord(current.tablename.toString()).get(current.documentkey.toString()) |
| **Script** | function openRelatedRecord() { var \_grRecord = new GlideRecord('sys\_metadata\_link'); \_grRecord.addQuery('sys\_id', rowSysId \|| g\_form.getUniqueValue()); \_grRecord.query(); if (\_grRecord.next()) { var \_strTableName = \_grRecord.tablename.toString(); var \_strRecordSysID = \_grRecord.documentkey.toString(); g\_navigation.openPopup('/' + \_strTableName + '.do?sys\_id=' + \_strRecordSysID); } } |
## Create Application Files on Form View
In a list view of a non-artifact table (table NOT inheriting from **sys\_metadata**) you have the list [action "Create Application Files"](https://docs.servicenow.com/csh?topicname=t%5FIncludeApplicationData.html&version=latest). This is always super helpful if you want to add pure data records to an application (for example technical users for integrations) for easier transfer to the next instance and make sure those records definitely exist in the target instance.
Unfortunately, that action is not available in the form view. However, with a slight modification of the original UI Action you also make it available for the form view.
### UI Action
| **Table** | **global** |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Form context menu** | true |
| **Client** | true |
| **Onclick** | popAddMetadataDialog(); |
| **Condition** | !current.isMetadata() && current.canCreate() && !SNC.MetadataLinkUtil.isTableMetadataLinkExempt(current.getTableName()) |
| **Script** | function popAddMetadataDialog() { var dialog = new GlideModal('add\_selected\_metadata\_link\_dialog'); dialog.setTitle( new GwtMessage().getMessage('Create Application File from Record') ); dialog.setPreference('current\_table', g\_form.getTableName()); dialog.setPreference('sys\_id\_list', g\_form.getUniqueValue()); dialog.render(); } |
## Open in Instance
How often have you opened any configuration record in one instance and then the same record on a different instance for comparison reasons? Or the same for list views? A button that allows us to open the current URL on another instance would therefore be extremely helpful. And this is exactly what the following UI action offers.
### UI Action
| **Table** | **global** |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Form button** | true |
| **List banner button** | true |
| **Client** | true |
| **Onclick** | openInInstance() |
| **Condition** | gs.hasRole("admin") && !RP.isRelatedList() |
| **Script** | function openInInstance() { var \_gm = new GlideModal(); var \_strCurrentInstanceHost = top.location.host; var \_objInstanceProperties = { 'DEV': { color: '#b32400', host : 'mycompany-dev.servicenow.com' }, 'TEST': { color: '#b38300', host : 'mycompany-test.servicenow.com' }, 'PROD': { color: '#302f4b', host : 'mycompany-prod.servicenow.com' } }; var \_arrHtml = \['
https://www.servicenow.com/community/developer-articles/my-collected-list-of-useful-ui-actions/ta-p/2911821
Maik Skoddow