- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 12:17 AM
Hi Experts,
We have checkbox variable on group table i.e. u_approval.
We want to have if script in workflow which will check if employee_name is member of group having u_approval as true. If yes the if check activity output should be yes orelse no.
I have written below script but inspite of employee being member of group having u_approval true the output is going to no.
answer = ifScript();
function ifScript() {
var userName = current.variables.employee_name;
var userGroupGR = new GlideRecord("sys_user_grmember");
userGroupGR.addQuery("user.name", userName);
userGroupGR.query();
while (userGroupGR.next()) {
var groupGR = new GlideRecord("sys_user_group");
if (groupGR.get(userGroupGR.group) && groupGR.u_approval) {
return "yes"; // Return "yes" if any group has u_approval true
}
}
return "no"; // Return "no" if no approved group is found
}
Please advice
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 02:45 AM
Hi @Ankita Gupte ,
What is the type of employee_name field, if it is a reference field then your script will always return "no". In that case you have to modify your script like below -
answer = ifScript();
function ifScript() {
var userName = current.variables.employee_name;
var userGroupGR = new GlideRecord("sys_user_grmember");
userGroupGR.addQuery("user", userName);
userGroupGR.query();
while (userGroupGR.next()) {
var groupGR = new GlideRecord("sys_user_group");
if (groupGR.get(userGroupGR.group) && groupGR.u_approval) {
return "yes"; // Return "yes" if any group has u_approval true
}
}
return "no"; // Return "no" if no approved group is found
}
Hope this help you.
Regards
Moin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 01:21 AM
Hi
If "employee_name" is reference variable. Try this
userGroupGR.addQuery("user", userName);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 02:45 AM
Hi @Ankita Gupte ,
What is the type of employee_name field, if it is a reference field then your script will always return "no". In that case you have to modify your script like below -
answer = ifScript();
function ifScript() {
var userName = current.variables.employee_name;
var userGroupGR = new GlideRecord("sys_user_grmember");
userGroupGR.addQuery("user", userName);
userGroupGR.query();
while (userGroupGR.next()) {
var groupGR = new GlideRecord("sys_user_group");
if (groupGR.get(userGroupGR.group) && groupGR.u_approval) {
return "yes"; // Return "yes" if any group has u_approval true
}
}
return "no"; // Return "no" if no approved group is found
}
Hope this help you.
Regards
Moin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 04:58 AM
This worked!
Thank you Moin Kazi.