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

Danish Bhairag2
Tera Sage
Tera Sage

Hi @SAI RAJU RAJANA ,

 

Try below code for restricting creation of users manually

 

(function executeRule(current, previous /*null when async*/ ) {
if (current.sys_created_by != 'system' || current.sys_created_by != 'admin') { //modify as per your need
        gs.addErrorMessage("Users cannot be manually added to any group. Please contact system administrator "); //modify if required
        current.setAbortAction(true); // prevent the update from happening
       gs.setRedirect(current); // redirected to current page 
    }


})(current, previous);

 

Thanks,

Danish

 

Amit Gujarathi
Giga Sage
Giga Sage

HI @SAI RAJU RAJANA ,
I trust you are doing great.
Please find the below revised code :

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

    // Replace 'your_condition_here' with the actual condition you want to check.
    // Example condition: prevent adding a user to a specific group
    // var your_condition_here = (current.group == '<group_sys_id>');

    if (your_condition_here) {
        // Replace 'Your error message here' with your custom error message.
        gs.addErrorMessage("Your error message here");

        // Abort the insertion of the record
        current.setAbortAction(true);

        // Redirect back to the group record
        gs.setRedirect(current);
    }

})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi @Amit Gujarathi 

I tried the same, User was not added, but the error message doesn't show up

 

Hi @SAI RAJU RAJANA,

 

Try to add current.addErrorMessage("Your error message here");  instead of  of gs.addErrorMessage("Your error message here"); 

 

you may get error message

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.

Prabhu9
Tera Expert

Hi, 

I've a similar requirement and same issue with me. Was there a solution for this ?