Query business rule to exclude tickets unless caller?

Sam Motley
Giga Guru

Hi All, 

 

Looking for some expertise on an issue. 

 

Context: We've onboarded a team into servicenow - they have their own table but use itil role and have a custom role. 

 

I've been asked to hide the incident table contents from their assignment groups - i've been able to achieve this using a before business rule query script below :

 

(function executeRule(current, previous /*null when async*/) {

    if(gs.getUser().isMemberOf('sys_id of group') && gs.getSession().isInteractive()){
        current.addQuery('assignment_group','sys_id of group');
    }
    else if(gs.getUser().isMemberOf('sys_id of group') && gs.getSession().isInteractive()){
        current.addQuery('assignment_group','sys_id of group');
    }
       else return;
 
My problem now is this hides all tickets including tickets they have raised - i don't want them to lose visibility of their ticket if they have raised it. 
I've tried adding a query for current.caller_id != gs.getUserID(); however this doesn't appear to work.
 
Has anyone got any ideas how i can get around this problem please? 
Thanks as ever 
 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Sam Motley 

try this and use OR condition

(function executeRule(current, previous /*null when async*/) {
    if (gs.getUser().isMemberOf('sys_id of group') && gs.getSession().isInteractive()) {
        var userID = gs.getUserID();
        var qc = current.addQuery('assignment_group', 'sys_id of group');
        qc.addOrCondition('caller_id', userID);
        qc.addOrCondition('opened_by', userID);
    } else {
        return;
    }
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Sam Motley 

try this and use OR condition

(function executeRule(current, previous /*null when async*/) {
    if (gs.getUser().isMemberOf('sys_id of group') && gs.getSession().isInteractive()) {
        var userID = gs.getUserID();
        var qc = current.addQuery('assignment_group', 'sys_id of group');
        qc.addOrCondition('caller_id', userID);
        qc.addOrCondition('opened_by', userID);
    } else {
        return;
    }
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

legend, thanks for sending this across exactly what i needed 

@Sam Motley 

Glad to help

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader