Set Field to Mandatory and Read Only

Evan Duran
Kilo Guru

I have this field I want to set to mandatory and read only because this information autopopulates, but if information doesn't autopopulate I don't want users to be able to submit form


Here is example of field not auto populating, it's set to read only because I don't user selecting their own VP and a VP approval is mandatory. So is there a way to set both mandatory and read only? As soon as I set to mandatory it gets rid of readonly

1 ACCEPTED SOLUTION

Zach Koch
Giga Sage
Giga Sage

You could use UI policies, but it would be much more straight forwards to create an onSubmit client script to check if the field is empty, and if it is, prevent the submission of the form.  Using a UI policy to achieve this, mandatory and read only are conflicting and it may cause unintended issues, especially if multiple fields are involved.

Here is a link to an example script you can use to check if the fields are empty on submit, and prevent the submission and show an error message.

Example script

If this resolved your issue, please mark this correct and helpful, thanks!

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

View solution in original post

3 REPLIES 3

EricDohr
ServiceNow Employee
ServiceNow Employee

Jesus Nava
Tera Guru

Check the scripts you created, what did you create to auto populate fhe variable? BR? client script? check those, the issue may be there.

Regards

Zach Koch
Giga Sage
Giga Sage

You could use UI policies, but it would be much more straight forwards to create an onSubmit client script to check if the field is empty, and if it is, prevent the submission of the form.  Using a UI policy to achieve this, mandatory and read only are conflicting and it may cause unintended issues, especially if multiple fields are involved.

Here is a link to an example script you can use to check if the fields are empty on submit, and prevent the submission and show an error message.

Example script

If this resolved your issue, please mark this correct and helpful, thanks!

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!