I want to Filed Mandatory and Read-Only

JVINAY
Tera Contributor

Hi Team,

 

My Requirement:

I want the field it_fun_org (a reference field to the Business_app table) to behave as follows:

  • It should be mandatory when the form loads.
  • It should be read-only always, regardless of whether it has a value or not.
  • The value is populated automatically (not by the user)

I have Tried below steps

  • I created a UI Policy with no conditions (so it always runs).
  • I added UI Policy Actions to make it_fun_org both mandatory and read-only.
  • The mandatory part works fine.
  • But the read-only setting is not taking effect — the field is still editable.

and I have created OnLoad Client script:

 

function onLoad() {
// Make the field mandatory
g_form.setMandatory('it_fun_org', true);

// Make the field read-only
g_form.setReadOnly('it_fun_org', true);
}

 

But its working on Form mandatory only not working on ReadOnly

Please help to How can  I achieve this.

5 REPLIES 5

J Siva
Tera Sage

Hi @JVINAY 
If both mandatory and read-only conditions are applied to a field, the mandatory configuration takes precedence. This is the expected OOB behavior. There's no practical logic in making a read-only field mandatory.

Please revisit your requirement—otherwise, simply make the field read-only.

 

Regards,
Siva

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @JVINAY 

Mandatory" and "Read-only" cannot be set at the same time.
You can only apply one of the two options at a given point.

*************************************************************************************************************
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]

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

Syed zabiullah
Tera Expert

@JVINAY 
You can use the following Client Script to make the it_fun_org field both mandatory and read-only, which works more reliably than a UI Policy:

 

g_form.setMandatory('it_fun_org', true);
g_form.setReadOnly('it_fun_org', true);   

This ensures the field is enforced correctly even if it's empty or auto populated.

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


Regards
Syed K

ali bhatti
Tera Contributor

Hi JVINAY,

Try to use time out function

function onLoad() {
// Make the field mandatory
g_form.setMandatory('it_fun_org', true);

// Use setTimeout to ensure it runs after the form loads
setTimeout(function() {
// Make the field read-only
g_form.setReadOnly('it_fun_org', true);
}, 100);
}

Or increase the ordor number of previouse UI police or client script 

it over hide other ui police or client scripts 

if it help full please accept the slution 

 

BR//
Saadat