"Cancel Change" UI action won't cancel until I fill out all mandatory fields (due to an onSubmit client script)

Shant Cancik
Tera Contributor

I have an onSubmit client script set up for change requests that makes fields mandatory. I also have a "Cancel Change" Ui action. My problem is that when I hit the "Cancel Change" UI Action, I'm still forced to fill in all mandatory fields before the cancellation occurs. Is there any way to work around this? Perhaps have the client script not activate if that button is pressed? I'm not sure what would be the best way to go about this issue.

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Shant,



You may find the below thread helpful.


Saving a record without populating all mandatory variables


Patrick Fedigan
Giga Guru

Instead of a Client Script to make fields mandatory I would use a Dictionary Override for each variable or a UI Policy with UI Policy Actions.



Hope this helps and let me know if you need more clarification! I think the cancel button might work if you make fields mandatory this way.



EDIT: Just tested this and it does not work


johnolivermendo
ServiceNow Employee
ServiceNow Employee

Hey Shant,



I'm assuming that you're using the OOB 'Cancel Change' UI Action that runs on the server side. My proposed solution is to create a new client-side UI Action that will replace the button on your change_request form which will turn of all mandatory fields on the form and then call the original server-side 'Cancel Change' UI Action.



1. Start by making some adjustments to your 'Cancel Change' UI Action


        - set 'Action name' to 'cancel_change'


        - unchecking the form context menu flag


Screen Shot 2017-04-19 at 3.37.37 PM.JPG



2. Create a new UI Action and make it like the one below:


        - client=true


        - form_context_menu=true


        - onClick contains your function call


        - gsftSubmit() is calling the action name set in your original UI Action - 'cancel_change'


Screen Shot 2017-04-19 at 4.48.38 PM.JPG


This should work regardless of how/where you set your mandatory fields for the form.


This was very helpful. Thank You very much!