Clear value on reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2020 01:36 AM
Hello All,
I have reference field by name field1 and 2 other fields by name field2 and field3. The values on field2, field3 are based on the reference field1. what I'm trying to achieve is if I have a value on field1 as xxxx, it sets field2, field3. later when I try to edit value on reference field1 to something else, i want the fields2, field3 to show no data on it (while i'm trying to change value on field1)
Field1 = reference field
Field2, Field 3 = text field
Any help?
Sowmya
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2020 03:00 AM
Cool,
Please close the thread by marking the appropriate response correct/helpful.
Thanks,
Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2020 09:05 AM
Hi,
Just checking to see if this is answered or you looking for some more information?
-Anurag

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2020 01:42 AM
Are field2 and field3 pulling data that originates from the field1 record? I'm not a fan of duplicating data when you could just display those reference field values on the form via dot walking. What is the purpose of pulling the text in this way?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2020 01:43 AM
Hi there,
Are these fields also dependend on each other?
If not, you could simply set up a UI Policy. No code needed. UI Policy triggered on field 1, UI Policy Actions for your other fields with the checkbox "Clear the field value" checked. That;s all.
No scripting needed. No client scripts whatever, just UI Policy.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2020 01:54 AM
Assuming you must be using onChange Client Script with getRefence() callback OR GlideAjax
Your onChange should look like this
It should clear field 2 and field 3 when Field1 is cleared out
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == ''){
g_form.clearValue('field2Name');
g_form.clearValue('field3Name');
}
// your logic here to set the values
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader