change state restrict users

sai190
Tera Contributor

Hi can one helpme with the requirment 

 


CHANGE: Restrict Users from Closing Change Records

 

No one, including the admin role, should be able to close a change.  For Change States, "Closed Successful" and "Closed with Defects", only the Change Manager role should be allowed to set these states. 

7 REPLIES 7

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

//     if (current.state == '3') // add the backend value for closed
// {

//     current.setAbortAction(true);
// }
    if ((current.state == '3' || current.state == '14') && !gs.getUser().hasRole('change_manager') && gs.getUser().hasRole('admin')) 
    {
        
        current.setAbortAction(true);
    }


})(current, previous);

 

 

This is not working for admin, admin is able to access the two options

Try this, please 

  if (((current.state == '3' || current.state == '14') && gs.getUser().hasRole('admin')) || ((current.state == '3' || current.state == '14')) && !gs.getUser().hasRole('change_manager') )
    { 
        current.setAbortAction(true);
    }

 

they will still be able to see the options but when they select it and save the record, they should see an error message.

hi thanks 

by the way the following code has worked and thanks so much for your help

 

function onLoad() {
   
    var flag = g_user.hasRole('change_manager');
    if(flag != true ||  g_user.hasRole('admin'))
        {
            g_form.removeOption('state', '3');
            g_form.removeOption('state', '14');            
        }  
}