Users able to see their incidents..

bhavyabansa
Tera Contributor

I have a requirement that user can see incidents for which he/she is Caller.Assigned_to , part of watchlist or part of a particular assignment group. Please help me with complete scenario.

1 ACCEPTED SOLUTION

amitshishod
Tera Guru

Hello @bhavyabansa ,

You can use Before Query BR for the same.

Try using this script

current.addEncodedQuery("^watch_listLIKE" + gs.getUserID() + "^ORassigned_to=" + gs.getUserID() + "^ORassignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744" + "^ORcaller_id=" + gs.getUserID());
//In  Assignment group query part use your assignment group sys_id
Please mark my answer correct and helpful if it helps you.


View solution in original post

3 REPLIES 3

amitshishod
Tera Guru

Hello @bhavyabansa ,

You can use Before Query BR for the same.

Try using this script

current.addEncodedQuery("^watch_listLIKE" + gs.getUserID() + "^ORassigned_to=" + gs.getUserID() + "^ORassignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744" + "^ORcaller_id=" + gs.getUserID());
//In  Assignment group query part use your assignment group sys_id
Please mark my answer correct and helpful if it helps you.


Ankur Bawiskar
Tera Patron
Tera Patron

@bhavyabansa 

there is already OOB Query BR on incident table which does the caller, assigned to and watch list logic

You can enhance it for assignment group

Code in bold is enhanced one

Remember you will have to update table.None READ ACL as well

restrictIncidents();
function restrictIncidents() {
    if (!gs.hasRole("itil") && !gs.hasRole("sn_incident_read") && gs.isInteractive()) {
        //Do NOT restrict Incidents if SPM premium plugin is active AND user has the service_viewer role.
        if (GlidePluginManager.isActive('com.snc.spm') && gs.hasRole('service_viewer'))
            return;
        if (GlidePluginManager.isActive('sn_fsm_itsm_mng') && gs.hasRole('wm_ext_agent'))
            return;
        // STRY52118544: ham_user is added to support incident read for reporting on HAM store app
        if (GlidePluginManager.isActive('com.sn_hamp') && gs.hasRole('sn_hamp.ham_user')) {
            return;
        }
        // DEF0330091: Allow query on OT Incident with sn_ot_incident_read role
        if (GlidePluginManager.isActive('com.sn_ot_inc_mgmt') && gs.hasRole("sn_ot_incident_read"))
            return;

        // Responders should be able to access all incidents
        if (gs.hasRole("sn_sow_srm.srm_responder")) {
            return;
        }
           
        var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
   
        var u = gs.getUserID();
        current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u).addOrCondition('assignment_group.sys_id', 'IN', groups.toString());
    }
}

ACL - update this OOB ACL

https://instanceName.service-now.com/nav_to.do?uri=sys_security_acl.do?sys_id=7da3bda1c0a801667dc88c1e9527f776

        var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
        current.opened_by == gs.getUserID() || current.caller_id == gs.getUserID() || current.watch_list.indexOf(gs.getUserID()) > -1 || groups.indexOf(current.assignment_group.toString()) > -1;

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

Viraj Hudlikar
Giga Sage

@bhavyabansa 

 

Existing BR which Ankur mentioned can be utilized but if you are looking for particular group person can view it then store sys_id of those group in comma separated under system properties and call it in code provided by Ankur.

 

In BR to call property syntax is as below:

 

gs.getProperty('yourPropertyName')

 

 

 so last line where the query is return will be like 

 

current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u).addOrCondition('assignment_group.sys_id', 'IN', gs.getProperty('YourPropertyName'));

 

 

 As well same in ACL can be done if you want specific group to be checked

 

current.opened_by == gs.getUserID() || current.caller_id == gs.getUserID() || current.watch_list.indexOf(gs.getUserID()) > -1 || groups.indexOf(gs.getProperty('yourPropertyName')) > -1;

 

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.