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')); 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' +};