How to check the user with user groups
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 11:09 PM
Hi Team,
Can you please help me on the below query.
I have written script when snapshot required option is selected i can able to select the requested item number for this i have add filter like created by me and active is true it show the requested umber based on this filter.
Now i want to add if the users is part of any of this group can able to select the request item number Tools & Auto - Automation - MinAu,Hosting - Platform - Hypervisor MinAu,Hosting - Hypervisor
(function executeRule(current, previous /*null when async*/ ) {
var ritm = current.variables.request_number;
var ritm1= current.number;
var rn = new GlideRecord('u_request_number');
rn.addQuery('sys_id', ritm);
rn.query();
if (rn.next()) {
var ext = rn.u_extension;
var uext = ext + 1;
var ext_ritm=ritm1;
}
rn.u_extension = uext;
rn.u_extension_ritm =ext_ritm;
rn.update();
})(current, previous);
i have written above script i want to add my new condition in the same script. please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 11:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 12:03 AM
so basically you want to add filter on some field.
but the script you shared doesn't relate to it.
Can you explain in detail your business requirement?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 12:47 AM
Hi @nikhitha24 ,
I trust you are doing great.
Please find the updated script
(function executeRule(current, previous /*null when async*/) {
var ritm = current.variables.request_number;
var ritm1 = current.number;
var rn = new GlideRecord('u_request_number');
rn.addQuery('sys_id', ritm);
rn.query();
if (rn.next()) {
var ext = rn.u_extension;
var uext = ext + 1;
var ext_ritm = ritm1;
}
// Check if the user is part of the specified groups
if (isUserInGroups(current.opened_by)) {
rn.u_extension = uext;
rn.u_extension_ritm = ext_ritm;
rn.update();
}
})(current, previous);
// Function to check if the user is in any of the specified groups
function isUserInGroups(userId) {
var groupNames = [
"Tools & Auto - Automation - MinAu",
"Hosting - Platform - Hypervisor MinAu",
"Hosting - Hypervisor"
];
var userGrp = new GlideRecord('sys_user_grmember');
userGrp.addQuery('user', userId);
userGrp.query();
while (userGrp.next()) {
var grp = new GlideRecord('sys_user_group');
grp.get(userGrp.group);
if (groupNames.indexOf(grp.name) !== -1) {
return true; // User is in one of the specified groups
}
}
return false; // User is not in any of the specified groups
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi