Clearing values with onCellEdit Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2018 09:57 AM
Hi Everyone,
I have a List field on a form that reveals additional fields with a UI Policy if the List contains "Other". If "Other" is deleted from the List, I want to clear the additional fields, but can't seem to get it to work with an onCellEdit client script.
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
if(g_form.getValue('x_dnf_gw_found_non_medicare_coverage','CONTAINS','other')) {
g_form.clearValue('x_dnf_gw_found_name_of_other_insurance');
g_form.clearValue('x_dnf_gw_found_policy_number');
}
callback(saveAndClose);
}
I've never actually used an onCellEdit client script so I'm pretty sure my script is incorrect. I used nearly the same script for onChange, but that would clear the additional fields as I added more selections to my List, which is not what I want.
Any advice here? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2018 10:04 AM
Hi Yundlu,
Are you running the onCell edit on the field "x_dnf_gw_found_non_medicare_coverage"? If yes then there is no need to getValue again. Also it seems the syntax of g_form.getValue() with contains method is not proper.
Also I checked the clearValue won't work like that I guess.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
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
07-10-2018 10:13 AM
Hey Ankur, thanks! Yes, the onCEllEdit is on that field, but don't I have to write that if statement in order to specify that it runs when "Other" is not included? Any advice on how you would script it? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2018 10:47 AM
Hi Yundlu,
I will check and let you know tomorrow.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader