Query business rule is not allowing the "requested for" to see catalog task

Rhonda9
Tera Expert

Hello,

 

I am trying to add an additional condition to my query business rule that will restrict the catalog only users with the pso_info_security role, It is restricting to the role and opened by but not when I add "requested_for" into the business rule.     When I add the requested for, the restriction no longer works. What am I doing wrong?  I removed the extra condition.   Please help.

(function executeRule(current, previous ) {

if(!gs.hasRole("pso_info_security")) { //the user is not a member of pso_fraud or information security or an admin
var userID=gs.getUserID();
var itemID='448d32c91bdda214d058c992604bcb28';

var encodedQuery="request_item.cat_item !="+ itemID + "^ORrequest_item.opened_by=" +userID;
current.addEncodedQuery(encodedQuery);

}
})(current, previous);
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Rhonda9 

try this

(function executeRule(current, previous) {
    // If the user does NOT have the pso_info_security role
    if (!gs.hasRole("pso_info_security")) {
        var userID = gs.getUserID();
        var itemID = '448d32c91bdda214d058c992604bcb28';

        // Only allow if the user is opened_by or requested_for
        // Block the item for others
        var encodedQuery = "request_item.cat_item!=" + itemID +
                           "^ORrequest_item.opened_by=" + userID +
                           "^ORrequest_item.requested_for=" + userID;

        current.addEncodedQuery(encodedQuery);
    }
})(current, previous);

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

View solution in original post

12 REPLIES 12

@Rhonda9 

which opened_by are you referring? sc_task or the sc_req_item?

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

Thank you so much Ankur,  this works the the only thing I did was changed the dot walk field from requested_item to request.

sunil maddheshi
Tera Guru

@Rhonda9 

Please try with below script and let me know:

(function executeRule(current, previous) {

    if (!gs.hasRole("pso_info_security")) {
        var userID = gs.getUserID();
        var itemID = '448d32c91bdda214d058c992604bcb28';

        // Only show the catalog item if user is the opened_by or requested_for
        var encodedQuery = "cat_item!=" + itemID + "^ORopened_by=" + userID + "^ORrequested_for=" + userID;
        current.addEncodedQuery(encodedQuery);
    }

})(current, previous);

Please mark correct/helpful if this helps you!