Onchange client script to make fields readonly after entry

pratyu
Kilo Explorer

Hello I have a requirement where on service portal record producer form , when the user enter a data in a field and select the next field it should be readonly , is this possible ? if yes can some one help me with the code 

 

Thanks in advance 

4 REPLIES 4

Brian Lancaster
Tera Sage

This is an on change script I have on a variable called first_name.  Once the filed has something in it it becomes read only.  Note that you have to make sure the UI Type on your client script is All.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
if (newValue != ''){
g_form.setReadOnly('first_name', true);
}
}

Thanks for the reply but i have 17 variables , is there any way we can do this to all variables in one client script instead of creating 17 on change client scripts, for each variable ?

Sure Pratyu... see the snap

find_real_file.png

Provide variable name of last order

I'm not sure this is possible as a client script would need to be an on change and you can only run that against 1 variable.  I'm wondering why you have this requirement.  What if a user enters something into variable A and then goes the variable B.  If they realize what they put into variable A is incorrect they have no way to change it.  This is usually not best practice.