state closed= read only

Shir Sharvit
Tera Contributor

Hi

 

I need that when the state=closed then all the fields in the Incident form will become read only

I am attaching the code:

ShirSharvit_0-1700485379856.png

 

This is the result, but I need the two fields that are not yet read-only to also be read-only
(service, service offering)

 

ShirSharvit_1-1700485413728.png

 

Thank.shir

 

7 REPLIES 7

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Shir Sharvit ,

 

That is because they are mandatory hence they are not becoming read only.

 

can u try making them as Mandatory false

just add this line after 4th line in your existing code

 

 

g_form.setMandatory(field[x],false)

 

 

Thanks,

Danish

 

It doesn't work for me, can you write down the code and where to add it?


function onLoad() {
if (g_form.getValue('state') == 7) { //state is closed
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
}
}

Hi @Shir Sharvit ,

 

function onLoad() {
if (g_form.getValue('state') == 7) { //state is closed
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setMandatory(fields[x],false);
g_form.setReadOnly(fields[x], true);
}
}
}

 

Thanks,

Danish

 

Hi @Shir Sharvit ,

 

If our responses helped u please mark it as Solution Accepted as it will help others to find the correct answer.

 

Thanks,

Danish