Auto clear variable value if dependent variable is cleared
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 12:02 AM
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.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 12:13 AM
add the below lines of code
if (newValue == ""){
g_form.setReadOnly(<owner variable>, false);
g_form.setValue(<owner variable>, "");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 12:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 12:15 AM
Hi,
you can make the field editable again and clear the value
share your existing script here
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader