Auto clear variable value if dependent variable is cleared

Akki1
Tera Contributor

Hi,

I have 2 fields which are reference type

1. Mob_id(optional and reference) --Optional

2. Owner(reference ti sys_user) ---Mandatory

So if I select some Mob_id it has a field Manager which will get auto populated in owner variable on selection and make owner field read only and if there is no Mob_id selected then it owner is not read only.

I have written onChange Client Script and doing callBack to get Manager value but suppose if i select Mob_id then owner is populated and is made read only and now if I remove the Mob_id i.e if I clear that value which i selected then Owner field still has that value and it is not getting editable as well.

 

 

 

3 REPLIES 3

suvro
Mega Sage

add the below lines of code

if (newValue == ""){

g_form.setReadOnly(<owner variable>, false);

g_form.setValue(<owner variable>, "");

}

Maroof Ali
Tera Contributor

Create OnChange client script and select field . varibale1

find_real_file.png

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can make the field editable again and clear the value

share your existing script here

Regards
Ankur

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