Prevent save/update/submit if field value not valid

tommyjensen
Giga Expert

I want to validate a field for duplicate entry before saving the record.

So I would like a client script to validate the value and if the value is not valid I will display a field message (got that part) but then I want to prevent a save/submit to be performed. How can I do that?

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi Tommy,



If you're trying to do this validation from an onSubmit client script, I believe you can then return false within your script when the value is not valid and the submission will be stopped.



Thanks,


Berny


View solution in original post

8 REPLIES 8

Govind Kumar S1
Kilo Guru

Hi Tommy ,



can you please some more information like, on which table you are working(if your field , on which table..)



we have OOB unique index on some fields which does not duplicate value on that field Unique Index - ServiceNow Wiki .



you need to write a script , which will query database to check whether that value is already present or not, if present then abort the insert action.




Thanks & Regards


Govind Kumar Sharma



PS: Hit like, Helpful or Correct depending on the impact of the response.


Unique key index will not work for me because in some cases I will allow duplicate.


bernyalvarado
Mega Sage

Hi Tommy,



If you're trying to do this validation from an onSubmit client script, I believe you can then return false within your script when the value is not valid and the submission will be stopped.



Thanks,


Berny


Thanks.