Show records if user is member of its assignment group

Aruna Sree Yela
Tera Guru

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:) 

 

1 ACCEPTED SOLUTION

Gangadhar Ravi
Giga Sage
Giga Sage

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);

View solution in original post

5 REPLIES 5

Gangadhar Ravi
Giga Sage
Giga Sage

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);