Need help in Business Rule

nameisnani
Mega Sage

Hi Team , 

 

can any one please help me on this request?

 

 Incidents which are assigned to CFS-CFSEdge-SUP limit view to the Opened By and the Caller and CFS-CFSEdge-SUP grp members

 

nameisnani_0-1738048362746.png

 

nameisnani_1-1738048429718.png

 

I have configured :- Before - query 

 

condition - !gs.getUser().isMemberOf('CFS-CFSEdge-SUP')

(function executeRule(current, previous /*null when async*/ ) {
    if (!gs.getUser().isMemberOf('CFS-CFSEdge-SUP')) {
        // Check if the incident assignment group is not CFS-CFSEdge-SUP
        var grpCondition = current.addNullQuery('assignment_group').addOrCondition('assignment_group', '!=', '6b9033d187c72550141931140cbb35e1');
        
        // Check if the business service is not CFS Edge Production
		// SNC Debug - start
        //current.addQuery('business_service', '!=', 'CFS Edge Production');
		current.addNullQuery('business_service').addOrCondition('business_service', '!=', 'CFS Edge Production');
		// SNC Debug - end
    }
	//gs.addInfoMessage(current.getEncodedQuery());
})(current, previous);

 

 

 

If any end user - raising incident from the portal , 

 

coming below error , 

 

nameisnani_2-1738048705560.png

 

 can anyone please modify my script . so that end user can see their incident , 

21 REPLIES 21

@nameisnani 

you can enhance the query BR as per your requirement.

I believe I provided enough guidance in helping and directing you.

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

@Ankur Bawiskar 

 

could you please provide me the updated script ? for me ! , i have tried not working 

restrictIncidents();

function restrictIncidents() {
    // if (!gs.hasRole("itil") && !gs.hasRole("sn_incident_read") && gs.isInteractive()) {

		// if member then do this else use the OOB logic
        if (gs.getUser().isMemberOf('CFS-CFSEdge-SUP')) {
            var u = gs.getUserID();
            current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("assignment_group.name", "CFS-CFSEdge-SUP");
        } else {
            //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 u = gs.getUserID();
            current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u);
        }
    }
}

 

 

could you please update my script  

@nameisnani 

try this

restrictIncidents();

function restrictIncidents() {
    // if (!gs.hasRole("itil") && !gs.hasRole("sn_incident_read") && gs.isInteractive()) {

    // if member then do this else use the OOB logic
    if (gs.getUser().isMemberOf('CFS-CFSEdge-SUP') && !gs.hasRole('itil')) {
        var u = gs.getUserID();
        current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("assignment_group.name", "CFS-CFSEdge-SUP");
    } else {
        //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 u = gs.getUserID();
        current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u);
    }
}
}

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

Hi @Ankur Bawiskar 

 

As per your instructions, I have updated BR like below.

restrictIncidents();

function restrictIncidents() {
    // if (!gs.hasRole("itil") && !gs.hasRole("sn_incident_read") && gs.isInteractive()) {

    // if member then do this else use the OOB logic
    if (gs.getUser().isMemberOf('CFS-CFSEdge-SUP') && !gs.hasRole('itil')) {
        var u = gs.getUserID();
        current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("assignment_group.name", "CFS-CFSEdge-SUP");
    } else {
        //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 u = gs.getUserID();
        current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u);
    }
}
//}

 

nameisnani_0-1738124992641.png

 

 

 

Tested :- 

 

I have impersnated with the user who don't have ITIL access . 

nameisnani_1-1738125176082.png

user who raised the incident, can able to view incident which is assigned edge group .

 

Now , edge grp members are not able to see the incidents , and ITIL users can able to view . which is incorrect 

@nameisnani 

I believe I provided you the right direction for your requirement.

All agents who work on incident have itil role so you need to ensure you handle all the cases

1) if logged in user is ITIL and not member of that group

2) logged in user is ITIL and member of that group

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