Lock down change states for users with change_management role

ebaileyybs
Tera Expert

Hi,

I am looking to lock down certain states available for selection within the change state field. Please see below options;

find_real_file.png

I would like for 'ITIL' users to only be able to select the following states;

Draft

Review

Closed

Users with the change_management role should be able to select any of the above states.

Any help with this would be greatly appreciate.d

Kind regards,

Emma

35 REPLIES 35

This is an onchange script on the Type field for your table and view



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


if(!isLoading)



{



if(newValue=='Normal')   //adding condition for type



{



if(g_user.hasRole('itil') && !(g_user.hasRole('change_management')))



{//add all states that you want to remove



g_form.removeOption('state', '-4');


 


g_form.removeOption('state', '-3', '');


 


g_form.removeOption('state', '-2');


 


g_form.removeOption('state', '2');


 


g_form.removeOption('state', '-1');





}



}



else if(newValue!='Normal')



{



g_form.clearOptions('state');


 


g_form.addOption('state', '-4', 'Approval Requested');


 


g_form.addOption('state', '-3', 'Approved');


 


g_form.addOption('state', '-2', 'Scheduled');


 


g_form.addOption('state', '2', 'In Progress');


 


g_form.addOption('state', '-1' , 'Completed');  





}



}


 


}  


-Anurag

Harish Murikina
Tera Guru

disableOption();




function disableOption()


{


    var fieldName = 'state';


      var control = g_form.getControl(fieldName);


      if (control && !control.options)


          {


                      var name = 'sys_select.' + this.tableName + '.' + fieldName;


                      control = gel(name);


               


          }


          if (!control)


          return;




          if (!control.options)


          return;




          var options = control.options;



        for (var i = 1; i < options.length; i++)


        {


           


              var option = options[i];


              //alert('hello'+ control.id);


              control.options[i].disabled = 'true';


       


          }


}



This is code work for disable all choices means un selectable all drop downs . What you can do is give if condition and check user have ITIL role if yes disable particular options


Harish Murikina
Tera Guru

The below code should work in your case




disableOption();




function disableOption()


{


    var fieldName = 'u_status';


      var control = g_form.getControl(fieldName);


      if (control && !control.options)


          {


                      var name = 'sys_select.' + this.tableName + '.' + fieldName;


                      control = gel(name);


               


          }


          if (!control)


          return;




          if (!control.options)


          return;




          var options = control.options;



        for (var i = 1; i < options.length; i++)


        {


           


              var option = options[i];


              alert('hello'+ options[i].value);


            if(g_user.hasRole('itil') && (options[i].value == "Draft" || options[i].value == 'Review' || options[i].value == 'Closed'))


          {


              control.options[i].disabled = 'true';


            }


       


          }


}


Artemis15
Kilo Guru

Hi Emma,



You can disable the option based on conditions.



Thanks,


Akash Rajput


abuthahir
Tera Expert