Service Catalog workflow with country restrictions

Mattikus4901
Tera Contributor

 

I have created a query business rule on the task  to restrict viewing of incidents, catalog requests, and catalog tasks based on user location. US users should be able to see all tasks created by users from all countries. UK users should only be able to see UK tasks. (see attached code).

This is causing the Requested Item  records to not be found in the service catalog workflows  because of the records being restricted by country. I am looking for some guidance to solve this issue. Any ideas???

 

 

1 REPLY 1

Anil Lande
Kilo Patron

Hi,

You need to apply the before query business rule on each table and conditions for specific table only. you will not get table name (taskType = incident, sc_request etc in before query).

 

I doubt it is going into the if conditions and your filter condition is set as default (LAST ELSE PART Always).

Also make sure your BR is only running by check gs.isInteractive()

Below is sample script for an incident table:

(function executeRule(current, previous /*null when async*/ ) {
    if (!gs.hasRole('admin') && gs.isInteractive()) {
        var userCountry = "";
        var query = "";
        var currentUser = gs.getUserID();
        var userGR = new GlideRecord('sys_user');
        if (userGR.get(currentUser)) {
            userCountry = userGR.location.country + '';
        }
        var userCountrySm = userCountry.toLowerCase();
        if (userCountrySm !== 'us' && userCountrySm !== 'united states' && userCountrySm !== 'usa' && userCountrySm !== 'united states of america') {
            query = "ref_incident.caller_id.location.country=" + userCountry;
            current.addEncodedQuery(query);
        }
    }
})(current, previous)

 

Note: Also make sure to include your login in existing Before Query BR (if any) for particular table. Creating multiple Before Query BR will not work as expected. If you are creating multiple BR then set proper order .

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande