Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Set all other fields read only when state is cancelled

moni170
Tera Contributor

I'm trying to set all fields read only when my state on incident form changes to canceled!!

Here's the code i've written and i'm currently using utah version but this code isn't working. Is there any possibility that getEditablefields() function doesn't work anymore?

If there's any other solution, do let me acknowledge.

That'll will be a great help.

1 ACCEPTED SOLUTION

DYCM
Mega Sage

Everything you have done is correct except for loop, you didn't set an original value to i.  1.png

Please replace: for (var i;i<field.length;i++) with for (var i=0;i<field.length;i++)

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   if(newValue == '8'){
	var field = g_form.getEditableFields();
	for (var i=0;i<field.length;i++){
		g_form.setReadOnly(field[i],true);
	}
   }
   
}

 

 

 

View solution in original post

6 REPLIES 6

desaiakash0
Tera Contributor

When I used this script my instance getting slow  and went in hung state 
can you explain why this happnes.

PravinHirekudi
Tera Contributor
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   if(newValue == '8'){
	var field = g_form.getEditableFields();
	for (var i=0;i<field.length;i++){
		g_form.setReadOnly(field[i],true);
	}
   }
   
}