make field read only

ammar_k
Tera Contributor

 

Hello,

I've created a catalog item and need to set a field to read-only. I attempted to use an onLoad client script with:

 
g_form.setReadOnly('variable_name', true);
 

However, this approach didn’t work.

The variable in question is a single-line text field and is not linked to a table field.

Do you know how I can achieve this?

4 REPLIES 4

Vasantharajan N
Giga Sage
Giga Sage

@ammar_k - Please use the "Catalog UI Policy" to make a field Readonly, Mandatory or Visible, instead of client script


Thanks & Regards,
Vasanth

PrashantLearnIT
Giga Sage

Hi @ammar_k 

 

Please use the Catalog UI Policy to make the variable readonly.

 

PLease mark my answer correct if it helps

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@ammar_k 

Are you sure that variable is not mandatory?

If it is mandatory then you cannot make it readonly

first make it non mandatory and then readonly

g_form.setMandatory('variable_name', false);
g_form.setReadOnly('variable_name', true);

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

AndersBGS
Tera Patron
Tera Patron

Hi @ammar_k ,

 

Why not utilizing a catalog UI Policy to make it read only? 

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/