Make section fields read only using onload client script

bandideena12
Tera Contributor

Hi,

In my table there are 2 sections, I need one field under the section, which should be read only when the state is assigned (after making the changes as state=assigned and saving/submitting the form). i tried the below code it is working for the fields not in section but not working to section fields. The script is...

 

var stat = g_form.getValue('state');
   
   if (stat == '3') {
           
            g_form.setReadOnly('triage_outcome_summary', true);
           
        }
Example: if I make the description field readonly using the above script its working, but if I select the field under the other section the script is not working. Please help me on this script.
8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@bandideena12 

are you sure the field name is correct?
Are you sure the field is from same table and not from a dot walked reference field?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@bandideena12 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Jyoti Jadhav9
Tera Guru

Hi @bandideena12 ,

 

Is there any UI policy applied on that field? Check the other client scripts. If UI Policy or multiple client scripts are present for that field then adjust the order. Also, verify the backend name of that field.

 

Please hit the like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

 

Thanks & Regards

Jyoti Jadhav

 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @bandideena12 

 

It might be issue with some other UI policy or script. Try to see what component running on this from.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************