- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2024 05:32 PM - edited ‎03-20-2024 06:19 PM
Hi everyone,
I'm trying to figure out why my field style script is not turning whatever 'retired' CI that is in the CI field on an interaction red. The fields below are the correct dot walk values. Not sure what I'm missing. Anything I can try?
Value: current.u_configuration_item.install_status.getDisplayValue() == 'Retired';
Style: color:red
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2024 07:55 PM
Try this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var ctrl = $('sys_display.' + g_form.getControl('u_configuration_item').id);
if (newValue === '') {
ctrl.style.backgroundColor = '';
return;
}
// Get the install status of the selected CI
var installStatus = '';
if (newValue) {
var ciGR = new GlideRecord('cmdb_ci');
if (ciGR.get(newValue)) {
installStatus = ciGR.install_status.toString();
}
}
// If the install status is 'Retired', set the text color of the CI field to red
if (installStatus == '7') {
// Set the text color of the CI field to red
ctrl.style.backgroundColor = 'red';
} else {
// Reset the text color to default if it's not retired
ctrl.style.backgroundColor = '';
}
}
A few things to note:
- You must unselect 'Isolate script' in the Client Script
- Using GlideRecord API on client script is not recommended. Consider using AJAX or g_scratchpad variable
- Since this is manipulating DOM, I wouldn't recommend it. It's likely that this won't work on other UIs such as Workspace.
- Consider using g_form.addErrorMessage or g_form.showFieldMsg
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2024 06:21 PM
Hey @JoeS43464908901,
I am assuming you have the 'isLoading' in the first if statement.
Delete that and it should work onLoad as well, if it still doesn't work, share the script, please.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2024 07:26 PM - edited ‎03-21-2024 07:50 PM
Did not work. Here's what I'm working with (have this on the Incident table too, see image).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2024 07:55 PM
Try this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var ctrl = $('sys_display.' + g_form.getControl('u_configuration_item').id);
if (newValue === '') {
ctrl.style.backgroundColor = '';
return;
}
// Get the install status of the selected CI
var installStatus = '';
if (newValue) {
var ciGR = new GlideRecord('cmdb_ci');
if (ciGR.get(newValue)) {
installStatus = ciGR.install_status.toString();
}
}
// If the install status is 'Retired', set the text color of the CI field to red
if (installStatus == '7') {
// Set the text color of the CI field to red
ctrl.style.backgroundColor = 'red';
} else {
// Reset the text color to default if it's not retired
ctrl.style.backgroundColor = '';
}
}
A few things to note:
- You must unselect 'Isolate script' in the Client Script
- Using GlideRecord API on client script is not recommended. Consider using AJAX or g_scratchpad variable
- Since this is manipulating DOM, I wouldn't recommend it. It's likely that this won't work on other UIs such as Workspace.
- Consider using g_form.addErrorMessage or g_form.showFieldMsg
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2024 08:17 PM
Thank you, it worked! Though like you said, not in Workspace view. Is there a way I could apply this to all views?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2024 02:31 PM
Hey @JoeS43464908901, no worries.
I could be wrong but I believe DOM manipulation doesn't work on Workspace.
But you can still use something like
g_form.showFieldMsg('u_configuration_item', 'This CI has been retired', 'info', false);
This works on both UIs, thanks