- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2017 10:33 AM
I'm trying to determine if the logged in user is a member of an assignment group that was selected so I can set the "assigned to" to that user (auto assigns to user if they're in the assignment group). I can't get either the condition "in" operator or indexOf() method to work. I've also tried adding method toString() to VAR assignments without success. Below is the code:
// Set assigned to if member of assignment group
var assignmentGroup = current.assignment_group;
var userGroups = gs.getUser().getMyGroups();
gs.log(">>> #1 assignmentGroup= " + assignmentGroup + " userGroups= " + userGroups);
if (assignmentGroup in userGroups) { //(assignmentGroup.indexOf(userGroups) >= 0) { <doesn't work either
gs.log(">>> #2 MATCH on Assignment Group!");
current.assigned_to = gs.getUserID();
} else { gs.log(">>> #3 NO match on Assignment Group!"); }
I get the following log entries:
Information | >>> #1 assignmentGroup= f0fc454d4f395a00a47a97dd0210c704 userGroups= [a54dfbc0a0a271007438a235437b7946, f0fc454d4f395a00a47a97dd0210c704] | ||
| >>> #3 NO match on Assignment Group! |
What am I doing wrong? Thanks for any assistance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2017 11:03 AM
Hi David,
Why not simply use:
if(gs.getUser().isMemberOf(current.assignment_group)){
//do something
}
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2017 10:41 AM
I failed to mention this is in a business rule, and the assignment groups is being set correctly. You can see from the log entries that the assignmentGroup value (sys ID) does match the second value in userGroups, but the condition always returns false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2017 11:03 AM
Hi David,
Why not simply use:
if(gs.getUser().isMemberOf(current.assignment_group)){
//do something
}
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2017 11:07 AM
Figured out indexOf() issue... I had the parameters backwards on the indexOf() method. The below condition works properly:
if (userGroups.indexOf(assignmentGroup) >= 0) {
If anyone knows why the "in" in the if condition doesn't work, I'd appreciate your reply.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2017 11:11 AM
I have not tried your code, but I am pretty sure you should not have spaces in there anyway:
if (assignmentGroupINuserGroups) {
harel