- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 10:11 AM
Hi,
I have 4 custom groups and the cases should be shown If the user is member of its assignment group.
To achieve this I have written a query business rule, it's work fine if the user is member of only 1 group among 4.
If he is member of more than 1 group, then no records are showing.
Can anyone help me on how can I achieve this.
Thanks in advance:)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 11:18 AM - edited 06-13-2024 11:19 AM
Issue with your current script is it adds AND logic and it don't return any records when user is members of multiple groups. Please try something like below. This script will work as expected by using the correct "OR" logic to combine the conditions.
(function executeRule(current, previous /*null when async*/) {
var queries = [];
if (gs.getUser().isMemberOf('CSM-1')) {
queries.push('assignment_group=0dd4a34f1b1cce10b5b24396b04bcb20');
}
if (gs.getUser().isMemberOf('CSM-2')) {
queries.push('assignment_group=cabe9f8f9798c250819b72ae215aa65a');
queries.push('attribute_name=Fact'); // for fact 2nd level
}
if (gs.getUser().isMemberOf('CSM-3')) {
queries.push('assignment_group=e4be1f8f9798c250819b72ae2153afff');
}
if (gs.getUser().isMemberOf('CSM-4')) {
queries.push('attribute_nameINPO,Description,Port');
}
if (queries.length > 0) {
var combinedQuery = queries.join('^OR');
current.addEncodedQuery(combinedQuery);
} else {
// Ensure no records are returned if user is not a member of any relevant group
current.addEncodedQuery('sys_id=IGNOREME');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 11:18 AM - edited 06-13-2024 11:19 AM
Issue with your current script is it adds AND logic and it don't return any records when user is members of multiple groups. Please try something like below. This script will work as expected by using the correct "OR" logic to combine the conditions.
(function executeRule(current, previous /*null when async*/) {
var queries = [];
if (gs.getUser().isMemberOf('CSM-1')) {
queries.push('assignment_group=0dd4a34f1b1cce10b5b24396b04bcb20');
}
if (gs.getUser().isMemberOf('CSM-2')) {
queries.push('assignment_group=cabe9f8f9798c250819b72ae215aa65a');
queries.push('attribute_name=Fact'); // for fact 2nd level
}
if (gs.getUser().isMemberOf('CSM-3')) {
queries.push('assignment_group=e4be1f8f9798c250819b72ae2153afff');
}
if (gs.getUser().isMemberOf('CSM-4')) {
queries.push('attribute_nameINPO,Description,Port');
}
if (queries.length > 0) {
var combinedQuery = queries.join('^OR');
current.addEncodedQuery(combinedQuery);
} else {
// Ensure no records are returned if user is not a member of any relevant group
current.addEncodedQuery('sys_id=IGNOREME');
}
})(current, previous);