Client Script - Alert message if updating to a specific state

fpuzon
Tera Contributor

Hi All,
I have an onSubmit client script that alert's the user when they attempt to submit/update a Change Request to a specific 'state' and they do not have a required role.   This seems to be working fine, however I wanted to add some logic where if the Change Request is already in that specific state, that they are able to save/update the record.   We just don't want them to be able to submit or update to that state from a previous state.       Hope that makes sense.   any help is appreciated.   Thanks everyone!

Fred

CAB Client Script.jpg

1 ACCEPTED SOLUTION

Hi Fred,



Great work!



As far as I know, disableOption() is not a method/function that comes OOB. Using g_form.removeOption() is the most common way.


View solution in original post

11 REPLIES 11

Hi Fred,



Great work!



As far as I know, disableOption() is not a method/function that comes OOB. Using g_form.removeOption() is the most common way.


Deepak Kumar5
Kilo Sage

var state = g_form.getControl('state');



  if(state.changed && g_form. --your condition)


{


veena_kvkk88
Mega Guru

Wouldn't an onChange client script on the state field solve your issue? Something like this:



if(newValue == '10' && !g_user.hasRole('cab_approver')){


      alert('Sorry! You are not authorized to change the state to "Ready for Deployment"');


      g_form.setValue('state', oldValue);


}



This will check for user role and the changed state, so if the state is already in that state, it wouldn't even kick off.


The catch with the onChange script is that it does not stop someone from submitting the form even after they set the wrong value. The only way around that is to clear the value and set the field to mandatory so they cannot submit until they pick the right value.


Of course, but i thought this line: g_form.setValue('state', oldValue); would solve that part, where it sets the state back to the older value?