I want to display Error Message when User is added to a group Manually.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 03:43 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 03:53 AM
Can you please share your code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 04:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 04:11 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 07:05 AM
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
}