Skip to content

Commit 5204396

Browse files
authored
Generate Clickable URL for a record for different UI (#2444)
* Get Clickable URL for the record for different views * Add documentation for GetClickableURL function Provides examples of how to use the GetClickableURL function in different UI contexts.
1 parent 0d7a3d6 commit 5204396

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Function that generates clickable HTML links to records in different UI contexts (Native UI, Workspace or Portal)
2+
3+
4+
5+
6+
Sample background Script:
7+
8+
var record_sysid = '';// add the record sys_id here.
9+
gs.info(new global.GetRecordDetails().getClickableURL('incident', record_sysid, 'INC- Workspace', 'workspace', 'cwf/agent'));
10+
11+
gs.info(new global.GetRecordDetails().getClickableURL('incident', record_sysid, 'INC- Portal', 'portal', 'sp'));
12+
13+
gs.info(new global.GetRecordDetails().getClickableURL('incident', record_sysid, 'INC - NativeUI', 'native'));
14+
15+
gs.info(new global.GetRecordDetails().getClickableURL('', record_sysid, 'INC - NativeUI', 'native'));
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var GetRecordDetails = Class.create();
2+
GetRecordDetails.prototype = {
3+
initialize: function() {},
4+
/*
5+
table - table name of the record.
6+
record - sysid of the record.
7+
display_text - Display text of the clickable URL
8+
urlUI - the URL Type - Accepts workspace/portal and native UI as default.
9+
uiName - mandatory parameter if urlUI is workspace or portal.
10+
11+
*/
12+
getClickableURL: function(table, record, display_text, urlUI, uiName) {
13+
try {
14+
var grRecord = new GlideRecord(table);
15+
if (grRecord.get(record)) {
16+
var instance_url = 'https://' + gs.getProperty('instance_name') + '.service-now.com/';
17+
var path;
18+
19+
if (urlUI == 'workspace' && uiName != '') {
20+
path = "now/" + uiName + "/record/" + table + "/" + record;
21+
} else if (urlUI == 'portal' && uiName != '') {
22+
path = uiName + "?sys_id=" + record + "&view=sp&id=ticket&table=" + table;
23+
} else {
24+
path = "nav_to.do?uri=" + table + ".do?sys_id=" + record;
25+
}
26+
// final URL
27+
var link = instance_url + path;
28+
var refLink = '<a href="' + link + '" target="_blank">' + display_text + '</a>';
29+
return refLink;
30+
31+
} else {
32+
gs.info('Record does not exist');
33+
return '';
34+
}
35+
} catch (e) {
36+
gs.info("Exception occured in getClickableURL method: " + e.message);
37+
return '';
38+
}
39+
},
40+
type: 'GetRecordDetails'
41+
};

0 commit comments

Comments
 (0)