I want to display Error Message when User is added to a group Manually.

SAI RAJU RAJANA
Tera Contributor

I created  a before insert BR on sys_user_grmember tables, based on few condition we need to restrict addition of the User

I used setabortaction(true) and addErrormessage()

it is not working as the page will redirect to group record

Does anyone the perfect solution for this?

9 REPLIES 9

Kalyani Jangam1
Mega Sage
Mega Sage

Hi @SAI RAJU RAJANA 

Can you please share your code?

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

    //Add your code here
   
if (condition) {
        gs.addErrorMessage("test");
        current.setAbortAction(true);
        action.setRedirectURL(previous);
       
    }

})(current, previous);

Hi @SAI RAJU RAJANA,

 

To restrict the addition of user in group try below script, It worked for me.

 

(function executeRule(current, previous /*null when async*/ ) {
if (current.state != 1) { //add your condition
        gs.addErrorMessage("Not allowed to submit "); //add your error message
        current.setAbortAction(true); // prevent the update operation
       gs.setRedirect(current); // redirected to current page 
    }


})(current, previous);

 

Reference for gs.setRedirect() is below.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0539962

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Hi @SAI RAJU RAJANA 

Please try below code

if(condition){

gs.addErrorMessage("Error message");

current.setAbortAction(true);

gs.setRedirect(current);

}

Please check below docs for more details

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0539962

}