From 075394e06d3edf970ae2809d916ec0b624a69bcc Mon Sep 17 00:00:00 2001 From: Rohila V <91993658+rohi-v@users.noreply.github.com> Date: Thu, 23 Oct 2025 19:43:17 +0530 Subject: [PATCH 1/2] Get Clickable URL for the record for different views --- .../Script Includes/GetClickableURL/scipt.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Server-Side Components/Script Includes/GetClickableURL/scipt.js diff --git a/Server-Side Components/Script Includes/GetClickableURL/scipt.js b/Server-Side Components/Script Includes/GetClickableURL/scipt.js new file mode 100644 index 0000000000..a8c73107e3 --- /dev/null +++ b/Server-Side Components/Script Includes/GetClickableURL/scipt.js @@ -0,0 +1,41 @@ +var GetRecordDetails = Class.create(); +GetRecordDetails.prototype = { + initialize: function() {}, + /* + table - table name of the record. + record - sysid of the record. + display_text - Display text of the clickable URL + urlUI - the URL Type - Accepts workspace/portal and native UI as default. + uiName - mandatory parameter if urlUI is workspace or portal. + + */ + getClickableURL: function(table, record, display_text, urlUI, uiName) { + try { + var grRecord = new GlideRecord(table); + if (grRecord.get(record)) { + var instance_url = 'https://' + gs.getProperty('instance_name') + '.service-now.com/'; + var path; + + if (urlUI == 'workspace' && uiName != '') { + path = "now/" + uiName + "/record/" + table + "/" + record; + } else if (urlUI == 'portal' && uiName != '') { + path = uiName + "?sys_id=" + record + "&view=sp&id=ticket&table=" + table; + } else { + path = "nav_to.do?uri=" + table + ".do?sys_id=" + record; + } + // final URL + var link = instance_url + path; + var refLink = '' + display_text + ''; + return refLink; + + } else { + gs.info('Record does not exist'); + return ''; + } + } catch (e) { + gs.info("Exception occured in getClickableURL method: " + e.message); + return ''; + } + }, + type: 'GetRecordDetails' +}; From f7228313bf0849dadbe84e7253b151958d711926 Mon Sep 17 00:00:00 2001 From: Rohila V <91993658+rohi-v@users.noreply.github.com> Date: Thu, 23 Oct 2025 19:48:14 +0530 Subject: [PATCH 2/2] Add documentation for GetClickableURL function Provides examples of how to use the GetClickableURL function in different UI contexts. --- .../Script Includes/GetClickableURL/readme.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Server-Side Components/Script Includes/GetClickableURL/readme.md diff --git a/Server-Side Components/Script Includes/GetClickableURL/readme.md b/Server-Side Components/Script Includes/GetClickableURL/readme.md new file mode 100644 index 0000000000..f01949ce12 --- /dev/null +++ b/Server-Side Components/Script Includes/GetClickableURL/readme.md @@ -0,0 +1,15 @@ +Function that generates clickable HTML links to records in different UI contexts (Native UI, Workspace or Portal) + + + + +Sample background Script: + +var record_sysid = '';// add the record sys_id here. +gs.info(new global.GetRecordDetails().getClickableURL('incident', record_sysid, 'INC- Workspace', 'workspace', 'cwf/agent')); + +gs.info(new global.GetRecordDetails().getClickableURL('incident', record_sysid, 'INC- Portal', 'portal', 'sp')); + +gs.info(new global.GetRecordDetails().getClickableURL('incident', record_sysid, 'INC - NativeUI', 'native')); + +gs.info(new global.GetRecordDetails().getClickableURL('', record_sysid, 'INC - NativeUI', 'native'));