Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Server-Side Components/Script Includes/GetClickableURL/readme.md
Original file line number Diff line number Diff line change
@@ -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'));
41 changes: 41 additions & 0 deletions Server-Side Components/Script Includes/GetClickableURL/scipt.js
Original file line number Diff line number Diff line change
@@ -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 = '<a href="' + link + '" target="_blank">' + display_text + '</a>';
return refLink;

} else {
gs.info('Record does not exist');
return '';
}
} catch (e) {
gs.info("Exception occured in getClickableURL method: " + e.message);
return '';
}
},
type: 'GetRecordDetails'
};
Loading