- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 12:55 PM
Hello all,
I am interested in hiding a specific value in the close_code dropdown field on the change_request form. The conditions are:
- Must have a related INC in the "Incidents Caused By Change" related list.
- If the user has the change_manager role then they can see the drop down value.
I have tried Client Scripts and UI Policies to no avail. Anyone else have any other ideas?
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 01:24 PM
@lonesoac01thanks, I modified the client script slightly (removed all the logs and error handling btw).
function onLoad() {
var currentUser = g_user.userID;
var currentSysId = g_form.getUniqueValue();
var ga = new GlideAjax('global.CheckRelatedRecordAndGroup');
ga.addParam('sysparm_name', 'getRelatedINCs');
ga.addParam('ChangeSYSID', currentSysId);
ga.addParam('UserSYSID', currentUser);
ga.getXMLAnswer(handleResponse);
function handleResponse(response) {
try {
var res = JSON.parse(response);
// Check if there is a related incident record and if the user is not a change manager
if (res.RelatedINCRecord === true && res.UsrIsChgMgr === false) {
// Hide specific drop-down option in the close_code field
hideCloseCodeOption('successful');
} else {}
} catch (e) {}
}
function hideCloseCodeOption(optionValue) {
g_form.removeOption('close_code', optionValue);
}
}
FYI, you might want to use a sys_id instead of the name when querying the group.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 01:18 PM
One option is a display rule to add a value to the scratchpad, and then an onLoad script.
(function executeRule(current, previous /*null when async*/ ) {
var relatedIncidentCount = new global.GlideQuery('incident')
.where('caused_by', current.getUniqueValue())
.count();
g_scratchpad.hasIncidentCausedByChange = Boolean(relatedIncidentCount);
})(current, previous);function onLoad() {
if(!g_user.hasRole('change_manager') || g_scratchpad.hasIncidentCausedByChange == false)
g_form.removeOption('close_code' , 'option_value_here')
}
