I have a scenario, where an user is part of hardware group and he wanted to update on sc_task record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 11:34 PM
I have a scenario, where an user is part of hardware group and he wanted to update on sc_task record to "software" group. But this group "Software" group should only be visible to the members of "Hardware" group and for other it should be hidden. Can you please assist me .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2024 03:25 AM
hi @HARITHA KHAREED
First, you need the Sys_ID of both the “Hardware” and “Software” groups. You can find these in the Groups table (sys_user_group).
- Name: Restrict Software Group Visibility
- Table: sc_task
- Type: onLoad
- Script:
(function onLoad() {
// Function to check if the current user is a member of the Hardware group
function isUserInHardwareGroup(callback) {
var hardwareGroupSysId = ‘YOUR_HARDWARE_GROUP_SYS_ID’; // Replace with your actual Hardware group Sys_ID
var userSysId = g_user.userID;
var gr = new GlideRecord(‘sys_user_grmember’);
gr.addQuery(‘group’, hardwareGroupSysId);
gr.addQuery(‘user’, userSysId);
gr.query();
gr.next();
var isInHardwareGroup = gr.hasNext(); // True if the current user is in the Hardware group
callback(isInHardwareGroup);
}
// Main logic to conditionally hide the Software group option
isUserInHardwareGroup(function(isEligible) {
// If the user is NOT in the Hardware group, remove the Software group option
if (!isEligible) {
var softwareGroupSysId = ‘YOUR_SOFTWARE_GROUP_SYS_ID’; // Replace with your actual Software group Sys_ID
g_form.removeOption(‘assignment_group’, softwareGroupSysId);
}
});
})();
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma