Last active
January 22, 2026 02:14
-
-
Save codaroma/8f28458071ab78ae20a35a1de56121a8 to your computer and use it in GitHub Desktop.
ServiceNow UI Action Open Relationship record from Related List Entry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // type: sys_ui_action | |
| // name: Open Relationship | |
| // table: sys_ui_related_list_entry | |
| // onclick: _<ui_action_sys_id>() eg: _7d3f6d1947e2b6105295e49b506d43e9() | |
| // condition: current.related_list.toString().startsWith("REL:") && current.related_list.toString().length === 36 | |
| // flags: client, show update, form link, list context menu | |
| async function _7d3f6d1947e2b6105295e49b506d43e9() { | |
| let table, id; | |
| if (globalThis.g_list && globalThis.g_sysId) { | |
| table = globalThis.g_list.getTableName(); | |
| id = globalThis.g_sysId; | |
| } else if (globalThis.g_form) { | |
| table = globalThis.g_form.getTableName(); | |
| id = globalThis.g_form.getUniqueValue(); | |
| } else return jslog("Unable to determine table & sys_id"); | |
| const field = "related_list"; | |
| const rl = ( | |
| await ( | |
| await fetch( | |
| "/api/now/table/" + | |
| table + | |
| "/" + | |
| id + | |
| "?sysparm_fields=" + | |
| field, | |
| { | |
| headers: { | |
| "X-UserToken": window.g_ck, | |
| }, | |
| }, | |
| ) | |
| ).json() | |
| ).result?.[field]; | |
| if (typeof rl === "string" && rl.startsWith("REL:") && rl.length === 36) { | |
| window.open("/sys_relationship.do?sys_id=" + rl.slice(-32)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment