Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Hide and display record per User Roles

jasoncao
Tera Contributor

Hi ! I need to display case records with Numbers starting with the word "RIQ" with the role "sn_customerservice.customer". Below is my code in Business Rule which is currently not working. Everyone please give me the solution to this problem!

Thanks !

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

var allowedRole = "sn_customerservice.customer";
var currentUser = gs.getUser();
var userRoles = currentUser.getRoles();

if (userRoles.indexOf(allowedRole) == -1) {
    if (c.data.list) {
        var filteredList = [];
        for (var i = 0; i < c.data.list.length; i++) {
            var record = c.data.list[i];
            if (record.number && record.number.value && record.number.value.startsWith("CS")) {
                filteredList.push(record);
            }
        }
        c.data.list = filteredList;
    }
}

})(current, previous);
1 REPLY 1

Sujatha V M
Kilo Patron
Kilo Patron

@jasoncao  Please refer the below link : 

 

https://www.servicenow.com/community/developer-forum/hide-show-record-as-per-roles/m-p/2245979

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.