Script include for If current logged in user in member of assignment group

DeepikaR1661877
Tera Contributor

Hi all,

I have the one recruitment , when the current logged in user having the "xyz" role, and the assignment group also having the same role if the condition is match then UI action visible to the incident table. i have write some code for that it's working inside the form when i am using gs.log method, but user having the role and and they not part of the assignment group even though the UI action are visible, any one help on this?

 

checkActionableUIActionVisibility: function(sirRecord) {
if (gs.hasRole('sn_si.sap_lob_analyst')) {
var groupSysId = sirRecord.assignment_group;
if (gs.getUser().isMemberOf(groupSysId)) {
return true;
}
}
return false;
},

 

 

 

UI Action condition

new ABC_SecurityIncidentUtil().checkActionableUIActionVisibility(current);

7 REPLIES 7

Sandeep Rajput
Tera Patron
Tera Patron

@DeepikaR1661877 Please update your function as follows.

 

 

checkActionableUIActionVisibility: function(sirRecord) {
if (gs.hasRole('xyz')&&gs.getUser().isMemberOf(sirRecord.assignment_group)) {
return true;
}
}

 

 

Hope this helps.

DeepikaR1661877
Tera Contributor

Hi @Sandeep Rajput ,

The above logic also not working , i can able to see the UI action button when the record assignment group doesn't have the the role

DeepikaR1661877
Tera Contributor

one more script i have tried but it's also not working,

checkActionableUIActionVisibility: function(sirRecord) {
if (gs.hasRole('sn_si.sap_lob_analyst')) {
var userSysId = gs.getUserID();

if (sirRecord.assignment_group) {
var groupGr = new GlideRecord('sys_user_grmember');
groupGr.addQuery('group', sirRecord.assignment_group);
groupGr.addQuery('user.active', true);
groupGr.addQuery('user.sys_id', 'IN', gs.getUser().getUserByRole('sn_si.sap_lob_analyst'));
groupGr.query();

if (groupGr.hasNext()) {
if (sirRecord.assignment_group == gs.getUser().getGroupID() || sirRecord.assigned_to == userSysId) {
return true;
}
}
}
}
return false;
}

Ravi Gaurav
Giga Sage
Giga Sage

Hi Deepika,

 

Can you try the below script ?

checkActionableUIActionVisibility: function(sirRecord) {

if (gs.hasRole('xyz')) {
// Get the sys_id of the assignment group from the sirRecord
var groupSysId = sirRecord.assignment_group;

// Check if the current user is a member of the assignment group
if (gs.getUser().isMemberOf(groupSysId)) {
return true;
}
}
return false; // Return false if conditions do not match
}

 

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/