How to make field read only in ui page until value is not selected

keshav77
Tera Contributor

Hi All,

 

I want to make fields only read-only on the basis of selection of that the second filed become editable.

for example I created 3 fields 1. caller  and 2. caller department and 3. call location.

Now I want caller department and caller location should be readonly until caller is selected how I can do that in ui page .

7 REPLIES 7

@Ankur Bawiskar      thankyou so much for your time but this is what I am looking for Solved: Re: Reference field read only issue in ui page - ServiceNow Community

@keshav77 

the links I shared should also work

In the 2nd link I shared it's making readonly editable based on condition, you can enhance it based on change of 1st field

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Bert_c1
Kilo Patron

I would use client scripts for this. One the runs 'onLoad' with the following logic:

 

function onLoad() {
	// Check if u_caller is empty
	var caller = g_form.getValue('u_caller');
	if (!caller) {
		g_form.setReadOnly('u_caller_department', true);
		g_form.setReadOnly('u_call_location, true);
	}
}

and another that runs 'onChange' for the "caller" field with logic:

function onChange() {
	// Check if u_caller is empty
	var caller = g_form.getValue('u_caller');
	if (!caller) {
		// clear any values in the two fields
		g_form.setValue('u_caller_department, '');
		g_form.setValue('ucall_location, '');
		g_form.setReadOnly('u_caller_department', true);
		g_form.setReadOnly('u_call_location, true);
	}
	else {
		g_form.setReadOnly('u_caller_department', false);
		g_form.setReadOnly('u_call_location, false);
	}
}