How to make a field readonly on a form if a template is applied

szollo
Kilo Contributor

Hello,

I have a custom reference field on a Change form, called Template. That field references System Definition->Templates. If I select a template, then some fields are populated on the form.

This all works fine, however I'd like to achieve that as soon as a field is populated(due to the selection of the template) make it read-only, not editable.

I've tried several options(client scripts, business rule, ACL, etc.), but none of them working as expected, although I'm new to ServiceNow, so it could be I was not doing it the right way.

Those fields that are populated due to the template can also be read-only by default, however when I was unable to achieve that(tried using ACLs, but I've found that read-only fields were not populated when I selected a template).

I need to make sure that as soon as a template is selected, the values that is populated on the form are not editable. I want to achieve this dynamically(without Saving the form).

Could you please give me some guidance on how to achieve this?

1 ACCEPTED SOLUTION

Right off my mind I would turn to ui polices. Not sure if you need to make 1 ui policy for each field or you can make only one with some fancy condition, haven't thought to so much on it. It's pretty much to choose from a few simple ones or one complicated one.



But it should work if you have a UI policy with condition that if field template isn't empty and field b(which the template fills) isn't empty, then read only sets on field B.



Shouldn't that work?



//Göran


View solution in original post

11 REPLIES 11

always fun to help and solve a problem 😃



//Göran


Rohit Sarkar1
Mega Guru

Why dont you try UI Policy... that is the one you are making the fields visible make them read only also expecting that these are the fields which are being populated once you select the template.


Unfortunately that doesn't work, as the field becomes read-only prior to the field getting populated by the selected template. So basically I'm going to end up with an empty field that is read-only.


abilash_017
Mega Guru

Hi Gergely,



you can achieve it using UI Policy.



Steps:



1. Go to UI policies in navigator.


2.Create new UI policy.


3. In that select table in which table it belongs to.


4. Add short description.


5. Give condition as :   "Template is not empty".


6.Save the form and then scroll down and in UI Policy actions --> add new


7. Select the "template" option and submit it.



Now check your requirement.


Comment back if you have any issues.



Hit Like/Helpful or correct based on the impact.


Hi Abilash,



Thank you for getting back to me!



Unfortunately that doesn't work(I tried your suggested steps). Please see my response to Rohit Sarkar.



Best regards,


Gergely