Need help on business rule, to not run on portal

ManishKumaJ
Tera Contributor

Hello All,

I have business rule to restrict users from creating incident who are not part of those 4 groups.

It basically check if loggedin  user is part of those 4 groups , if not then it will show info message and stops it from creating incident . But my issue here is we have record producer in portal which has those assignment group, this business rule shouldn't run on portal. It should allow any user to create the incident for those groups.
How can I achieve this?

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

    var currentUser = gs.getUser();
  var isServiceDeskUser = currentUser.isMemberOf('Tech Supp') || currentUser.isMemberOf('Irv Tech Supp') || currentUser.isMemberOf('Lou Tech Supp') || currentUser.isMemberOf('IT Service Desk');



   
    if (!isServiceDeskUser) {
        // Abort the action and add an error message
        current.setAbortAction(true);
        gs.addErrorMessage('Only Service Desk and Level 2 group members may Create or Update this Incident.');
      
    }

})(current, previous);
2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Try one of these if conditions to only execute the Business Rule script in the native UI.

(function executeRule(current, previous /*null when async*/ ) {
    if (gs.action.getGlideURI().toString().indexOf('sp') == -1) { //not Service Portal
        var currentUser = gs.getUser();
        var isServiceDeskUser = currentUser.isMemberOf('Tech Supp') || currentUser.isMemberOf('Irv Tech Supp') || currentUser.isMemberOf('Lou Tech Supp') || currentUser.isMemberOf('IT Service Desk');
        
        if (!isServiceDeskUser) {
            // Abort the action and add an error message
            current.setAbortAction(true);
            gs.addErrorMessage('Only Service Desk and Level 2 group members may Create or Update this Incident.');
        }
    }
})(current, previous);

 

(function executeRule(current, previous /*null when async*/ ) {
    if (GlideTransaction.get().getRequest().getHeader("referer").indexOf('esc') == -1) { //not Service Portal
        var currentUser = gs.getUser();
        var isServiceDeskUser = currentUser.isMemberOf('Tech Supp') || currentUser.isMemberOf('Irv Tech Supp') || currentUser.isMemberOf('Lou Tech Supp') || currentUser.isMemberOf('IT Service Desk');
        
        if (!isServiceDeskUser) {
            // Abort the action and add an error message
            current.setAbortAction(true);
            gs.addErrorMessage('Only Service Desk and Level 2 group members may Create or Update this Incident.');
        }
    }
})(current, previous);

 

I tried it, but still I am getting same error message