The CreatorCon Call for Content is officially open! Get started here.

I have a scenario, where an user is part of hardware group and he wanted to update on sc_task record

HARITHA KHAREED
Tera Contributor

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 .

1 REPLY 1

Deepak Shaerma
Kilo Sage
Kilo Sage

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