Reference Field on sys_user table does not show Hyperlink
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 01:53 AM
Hello community,
I've created a custom reference field (u_user) on task table. Reference is on sys_user table and calculated.
Calculated value:
(function calculatedFieldValue(current) {
var userSysId = '';
function getSysId(record, field) {
// Check if the field exists and return it in its original format
return record[field] ? record[field] : '';
}
// Check the task type and fetch the corresponding user SysID
if (current.sys_class_name == 'incident') {
var incidentRecord = new GlideRecord('incident');
if (incidentRecord.get(current.sys_id)) {
userSysId = getSysId(incidentRecord, 'u_affected_user');
}
} else if (current.sys_class_name == 'change_request') {
var changeRequestRecord = new GlideRecord('change_request');
if (changeRequestRecord.get(current.sys_id)) {
userSysId = getSysId(changeRequestRecord, 'requested_by');
}
} else if (current.sys_class_name == 'sc_req_item') {
var reqItemRecord = new GlideRecord('sc_req_item');
if (reqItemRecord.get(current.sys_id)) {
userSysId = getSysId(reqItemRecord, 'requested_for');
}
} else if (current.sys_class_name == 'sc_task') {
var scTaskRecord = new GlideRecord('sc_task');
if (scTaskRecord.get(current.sys_id)) {
var parentReqItem = new GlideRecord('sc_req_item');
if (parentReqItem.get(scTaskRecord.parent)) {
userSysId = getSysId(parentReqItem, 'requested_for');
}
}
} else if (current.sys_class_name == 'change_task') {
var changeTaskRecord = new GlideRecord('change_task');
if (changeTaskRecord.get(current.sys_id)) {
var parentChangeRequest = new GlideRecord('change_request');
if (parentChangeRequest.get(changeTaskRecord.parent)) {
userSysId = getSysId(parentChangeRequest, 'requested_by');
}
}
} else if (current.sys_class_name == 'incident_task') {
var incidentTaskRecord = new GlideRecord('incident_task');
if (incidentTaskRecord.get(current.sys_id)) {
var parentIncident = new GlideRecord('incident');
if (parentIncident.get(incidentTaskRecord.parent)) {
userSysId = getSysId(parentIncident, 'u_affected_user');
}
}
}
return userSysId; // Return the calculated sys_id value in its original format
})(current);
The objective is to save the user name in the custom field, depending on the process (Incident, Request or Change). Problem: When I go to task.list and display the u_user field, the correct name of the person appears, but it is not clickable (hyperlink missing).
Thank you and BR.
Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 02:12 AM
I believe the value is calculated when list is rendered and hence the link is missing. I need to explore much on this
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 02:14 AM
Okay, I roughly understand. How can I render it afterwards? In some cases the link is displayed. But in most cases it does not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 02:41 AM - edited 06-27-2024 02:45 AM
Pretty sure a Calculated field cannot be hyperlinked as you require, they are not a Reference type field.
It's difficult to understand your business case from the above, but my advice would be to avoid calculated fields altogether unless there is no other way of achieving your requirement. They are very resource intensive.
Have a read of this post on the evils of Calculated fields: https://www.servicenow.com/community/itsm-forum/calculated-fields-documentation/td-p/838796/page/1
Regards
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2025 01:56 PM
@Paul Curwen so basically is there any specific reason to why would some calculated fields miss link, my calculated field is a string type but strangely this column appears to be showing links on another table, but in some cases the links are missing so some records show just a normal string but other do show a link.