Skip to content

Commit 075394e

Browse files
authored
Get Clickable URL for the record for different views
1 parent 0d7a3d6 commit 075394e

File tree

1 file changed

+41
-0
lines changed
  • Server-Side Components/Script Includes/GetClickableURL

1 file changed

+41
-0
lines changed
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)