Help with a Before-Query Business Rule on the Task table

jlaue
Kilo Sage

Hello - 

We had created a few different Before-Query business rules for a few specific Assignment Groups, (non IT groups using ServiceNow).  The business rule will only show those specific groups incidents that are assigned to their group.  We originally had this business rule set to run on the Incident table, until we discovered if they query against the Task table or used VTBs against the task table that they would still see the Incident record and field values, but just could not open the record itself. 

We then changed the business rules to run on the Task table instead.  No issues with that until we launched our Service Catalog recently and now due to the business rules (verified by disabling them and testing) they are unable to properly utilize the Service Catalog - can't see their order, request item workflows don't kick off, no catalog tasks, etc.

While testing, I went into one of the business rules and in the Condition builder - I set it to Task Type is Incident, however that seemed to break the business rule in that it then just showed all the tasks and was not adhering to the script to only show the incidents assigned to their group. 

Maybe I need to put the task type condition in the 'Advanced' section of the Business Rule right above the Script field, but I am not sure what code to put in for 'task type is incident' in there?

I was hoping someone would be able to please help with this?  

Here is one of the 'Assignment Group visibility' business rules:

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

var u = gs.getUserID();

if (!gs.hasRole('admin') && gs.getSession().isInteractive()) {
if(gs.getUser().isMemberOf('bdaac8491303de003666b107d144b0c2')) {
current.addQuery('assignment_group', 'bdaac8491303de003666b107d144b0c2').addOrCondition("caller_id", u);
} else {
current.addQuery('assignment_group', '!=', 'bdaac8491303de003666b107d144b0c2').addOrCondition("caller_id", u).addOrCondition('assignment_group', '');
}
}

})(current, previous);

 

Thank you!

 

4 REPLIES 4

Brian Lancaster
Tera Sage

Putting it in the condition above the script would probably work better.  It should just be current.sys_class_name == 'incident'

Mike Patel
Tera Sage

try changing caller_id with ref_incident.caller_id

jlaue
Kilo Sage

Hello - thanks for the quick responses!  I tried both of these suggestions, both on their own and a combination, and unfortunately it is the same issue.  Once the condition is applied it is like it just disregards the business rule all together and just shows them every record.  If I pull the condition out, it is then only showing them the records assigned to their group.

Johannes Coetse
Kilo Expert

Hi,

 

Where you able to sort this out eventually? I have the same requirements currently albeit on a different custom field on the Task [task] table.

Also have the issue that it works great apart from the Caller and Requester not being able to see their own Incidents, Requested Items and Requests if the business rule is applied.

 

I've tried doing new GlideRecord() but doesn't seem to work and really don't want to create a BR for each table.

 

Any help would be appreciated if you found a solution.