Is it possible to make a field mandatory and read only in the form ? If yes what is the use ?

Karunakar3
Kilo Contributor

Is it possible to make a field mandatory and read only in the form ? If yes what is the use ?

1 ACCEPTED SOLUTION

Josh Virelli
Tera Guru

Hi Karunakar,

You can of course set a field to both Read-Only and Mandatory, however the Read-Only part will "win-out" against it. Meaning, even if there isn't a value in the field, you could still save the record. Just like Mandatory will win out over Visible.

I would rarely recommend using the checkboxes on the Dictionary Entry to set Read-Only and Mandatory, instead I'd recommend using a UI Policy.

I think there are very few use cases for making something Read-Only and Mandatory. One I can think of is if you want to ensure a field is always Mandatory, and there are cases that would change whether or not it is Read Only, but even then, I would think you could have the Mandatory set to true/false with the opposite of the same condition as the Read Only being set to true/false.

Is there a specific use-case you had in mind, or did you just want some thoughts on this? Let me know if I can assist further. 

If my answer was helpful or answered your question, please mark it as 'Helpful' or 'Correct'

Thanks!

Josh

View solution in original post

10 REPLIES 10

Josh Virelli
Tera Guru

Hi Karunakar,

You can of course set a field to both Read-Only and Mandatory, however the Read-Only part will "win-out" against it. Meaning, even if there isn't a value in the field, you could still save the record. Just like Mandatory will win out over Visible.

I would rarely recommend using the checkboxes on the Dictionary Entry to set Read-Only and Mandatory, instead I'd recommend using a UI Policy.

I think there are very few use cases for making something Read-Only and Mandatory. One I can think of is if you want to ensure a field is always Mandatory, and there are cases that would change whether or not it is Read Only, but even then, I would think you could have the Mandatory set to true/false with the opposite of the same condition as the Read Only being set to true/false.

Is there a specific use-case you had in mind, or did you just want some thoughts on this? Let me know if I can assist further. 

If my answer was helpful or answered your question, please mark it as 'Helpful' or 'Correct'

Thanks!

Josh

Hi Josh,

 

Thanks for the quick reply,  I need some scenarios where will we use mandatory and read only for a field in the form ??

 

Thanks in Advance

Hi @Josh Virelli - CloudPires - I have a case where I need a field within an application to be Read Only, unless they have a certain role, to be Mandatory. Using a UI Policy, i have it working when I have 1 role listed, but I'm unsure on how to write it for the 2nd role (where I need it to be mandatory. Lets say role is 'test_mandatory')...you have suggestions?

I've started with this:

function onCondition() {
if(g_user.hasRoleExactly('test_read_only'))
g_form.setMandatory('name', false);
g_form.setReadOnly('name', true);
}

Hey Mairvette,

If I'm understanding correctly, I think you would just add an Else If condition for that second role

function onCondition() {
if(g_user.hasRoleExactly('test_read_only')){
g_form.setMandatory('name', false);
g_form.setReadOnly('name', true);
}else if (g_user.hasRoleExactly('test_mandatory'){
g_form.setMandatory('name', true);
g_form.setReadOnly('name', false);
}
}

Let me know if that helps!

If my answer was helpful or answered your question, please mark it as 'Helpful' or 'Correct'

Thanks!

Josh