Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Clearing values with onCellEdit Client Script

yundlu316
Kilo Guru

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!

3 REPLIES 3

Ankur Bawiskar
Tera Patron

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

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

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!

Hi Yundlu,

I will check and let you know tomorrow.

Regards

Ankur

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