Hide UI Action button based on field value on Load after saving.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2024 12:30 AM
There is a ui action button Input Required (input_required) with some other conditions that needed. hence, they used onclick functions in script field.
Now my requirement is that I am using these Input Required button in change_request table.
It has one field requested_by (reference field).
if the user in the requested_by field is part of Software Group, then i want to hide the input_required button. It have to work when "onLoad" not onChange.
How can I achieve this using client script or Script include or both. what is the answer?
Please help me with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 12:08 AM
It's a ui action, so just use the condition field: !gs.getUser().isMemberOf('Software')
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 12:17 AM
But here i want to check the user in requested_by field is part of Software group.
Not the current user.
How can i achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 12:37 AM
Use this in the condition:
new UserGroupChecker().isRequestedByInGroup(current.sys_id, 'Software') == false
with this script include:
var UserGroupChecker = Class.create();
UserGroupChecker.prototype = {
initialize: function() {
},
isRequestedByInGroup: function(changeRequestId, groupName) {
var changeRequest = new GlideRecord('change_request');
if (changeRequest.get(changeRequestId)) {
var requestedBy = changeRequest.requested_by;
if (!requestedBy.nil()) {
var userGR = new GlideRecord('sys_user');
if (userGR.get(requestedBy)) {
var user = new GlideUser(userGR.sys_id);
return user.isMemberOf(groupName);
}
}
}
return false;
},
type: 'UserGroupChecker'
};
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 12:52 AM