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:59 AM
Hi @VullankiL
Script Include:
- Make sure the Script Include is marked as Client Callable.
- The isUserInSoftwareGroup method should accurately check the user's group membership.
var CheckSoftwareGroup = Class.create();
CheckSoftwareGroup.prototype = {
initialize: function() {},
isUserInSoftwareGroup: function(userId) {
var userGroup = new GlideRecord('sys_user_grmember');
userGroup.addQuery('user', userId);
userGroup.addQuery('group.name', 'Software Group'); // Replace with the exact name
userGroup.query();
return userGroup.hasNext();
}
};
Client Script:
- Verify that requested_by correctly retrieves the user reference.
- Ensure the GlideAjax call to the Script Include is correctly set up.
- Confirm that the button ID used in g_form.getControl('input_required') is correct and corresponds to the UI action button.
function onLoad() {
var requestedBy = g_form.getReference('requested_by', function(user) {
if (user) {
var ga = new GlideAjax('CheckSoftwareGroup');
ga.addParam('sys_id', user.sys_id);
ga.getXMLAnswer(function(response) {
if (response === 'true') {
var button = g_form.getControl('input_required');
if (button) {
button.style.display = 'none';
}
}
});
}
});
}
……………………………………………………………………………………………………
Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 01:11 AM
Still the input required button is not hiding when user in requested_by field is part of software group. i don't know where it is going wrong..