Make all form fields read-only

malaisamyj
Tera Contributor

Hi All,

I have one requirement as below,

Based on my workflow stage i need to make all fields readonly in one shot. But it should not make readonly on sys_created_on,sys_created_by,sys_updated_on and sys_updated_ by.

I have used the below code. But its making all fields including sys fields. Because   of which i am getting error" find_real_file.png"

var fields = g_form.getEditableFields();

for (var x=0; x < fields.length; x++){

  g_form.setReadOnly(fields[x],true);

}

i need code where except these fields("sys_created_on,sys_created_by,sys_updated_on and sys_updated_ by.") everything should be readonly in one shot.

If possible please help me?

Thanks,

Malaisamy

1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

You mean something like this is not enough?



for (var x=0; x < fields.length; x++){


  if (fields[x] != 'sys_created_on' && fields[x] != 'sys_created_by' && fields[x] != 'sys_updated_on' && fields[x] != 'sys_updated_by')


      g_form.setReadOnly(fields[x],true);


}


View solution in original post

5 REPLIES 5

Nithya Nagaraja
Giga Contributor

Or we can get all the editable form fields and then make them read only via onload client script

 

function onLoad() {
	var fields = g_form.getEditableFields();
	for (var x = 0; x < fields.length; x++) {
		// by default the mandatory fields can not be set as readonly
		// Make the field non-mandatory before making it readonly
		g_form.setMandatory(fields[x], false);
		g_form.setReadOnly(fields[x], true);
	}
}

 

Vinay Polisetti

Conyx IT Solutions | ServiceNow experts

vinay@conyxit.com