Having a UI Action validate fields before save.

ccajohnson
Kilo Sage

I have made a UI action button which changes the status of a record, then saves the record. Unfortunately any validations that should occur on save do not happen and we have a record with required fields not filled out that are not being reported on.

current.state='3'; //changes status to pending
current.u_status_detail='Review';
current.update();
action.setRedirectURL(current);

We use a client script to do the validation for this record state. I would like to be able to call this client script within the UI action rather than recreating the entire validation routine in the UI Action.

Please let me know if there is a way to force validation before the UI action saves.

5 REPLIES 5

coolboy
Mega Expert

i think you should click client option and then copy the code of ur validation(client scripts validation) in script area and wrap this in a function say validate(){code}.
And then in onclick juist pass call to validate function validate();


saranya7
Kilo Contributor

I think your point is correct.. but still the whole purpose wouldnt be served. since we select the client option it wont allow us to use any of the server side object like action.setRedirectURL or current.update().


ccajohnson
Kilo Sage

That seems to be the easiest way to go, but I do not want to have to maintain the validation code in two locations.


gaidem
ServiceNow Employee
ServiceNow Employee

http://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/