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

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);


}


Hi Sergiu,



Thanks for the response . it works superb..


Hi can you please help I am new to SN i want to do the same where do i write this code and is this the full code, I am trying to make my form read only at the draft stage

 

I would greatly appreciate your help

Hi Kiran,

 

Full code is here.

 

var fields = g_form.getEditableFields();

 

add your condition

 


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);
}