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

Chuck Tomasi
Tera Patron

Hi Fred,



I cannot think of a good way to get the previous value and detect changes in the client script. It might make more sense to prevent the user from doing something potentially harmful in the first place rather than let them and warn them. This offers a better user experience.



Possible ideas:


How about an onLoad client script that checks if the user has a role and makes the state editable, otherwise read-only.   Or if they don't have the role, remove the option, or hide the state if it's 10 and they don't have the role. That way they cannot change it, but it doesn't get changed either.


Hi Chuck,


Thanks for the quick reply.   I think I like your second recommendation where we disable that option.   Here is what I have put together, but I think I'm still missing something as the state still in not disabled:



onLoad.jpg



Any ideas?   Thanks in advance.



Fred


Have you added UI script for disableoption() ?


If not, Add it from below link from guru (Disabling/Enabling Options)


http://www.servicenowguru.com/scripting/client-scripts-scripting/removing-disabling-choice-list-opti...


So, I was able to remove the state with the below code, however when I use disableOption nothing happens.   User's can still select that state.  
removeOption.jpg




Any idea why disbaleOption wouldn't work?



Thanks,
Fred