- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 02:05 AM
Want to clear all fields value which is present on Form when we select other option.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 02:09 AM
Hi,
you can use something like this
var fields = ['fieldA','fieldB','fieldC','fieldD']; // store field names in array
for (var x = 0; x < fields.length; x++) {
g_form.clearValue(fields[x]);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 02:08 AM
Hi,
all fields means? do you have list of those?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 02:09 AM
Hi,
you can use something like this
var fields = ['fieldA','fieldB','fieldC','fieldD']; // store field names in array
for (var x = 0; x < fields.length; x++) {
g_form.clearValue(fields[x]);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 02:11 AM
Try below.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue == other)
{
var fieldArr = ['field1', 'field2',.....]; //add comma separated field names which you want to clear here
for (var i = 0; i < fieldArr.length; i++) {
g_form.clearValue(fieldArr[i]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 02:18 AM
Hi,
Just a word of caution: What if there is any read only field and you clear it , and now user cannot enter any new value also.
What about fields/ if any that get populated by logged in user detail or derived from other fields.
Fields that were saved in previous stages.
So make sure you know what you are doing and its effect in the long run.
-Anurag