Make Field Read Only according to the condition

Kumar887
Tera Contributor

Hi Community, Good Day!!!!
As we know that in incident table when we add value on Caller field then for some users, 'location' field's value auto-populates. So, in my requirement, if location field gets auto-populates, make it read-only, like in below:

Kumar887_0-1714398518375.png

 

 

and when 'location' does not gets auto-populates and user sets it manually, then make it editable even it is set.

Thanks in Advance!!

1 REPLY 1

Sujatha V M
Kilo Patron
Kilo Patron

@Kumar887  Create a client script on Incident table as below, 

 

Table : Incident [incident]

Type : onChange

Field name : Caller

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }

    var caller = g_form.getReference('caller_id', setLocation);
}

function setLocation(caller) {
    if (caller)
        g_form.setValue('location', caller.location);
		if(caller.location != ''){
			g_form.setReadOnly('caller_id.location', true);
		}
		else{
			g_form.setReadOnly('caller_id.location', false);
		}
}

 

Results : 

If location is not empty, make the field as read-only.

SujathaVM_0-1714458492204.png

 

If the location is empty, make the field as editable.

SujathaVM_1-1714458561206.png

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.