The CreatorCon Call for Content is officially open! Get started here.

Client script for clear fields value.

Shikha puri
Tera Contributor

Want to clear all fields value which is present on Form when we select other option.

1 ACCEPTED SOLUTION

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

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

all fields means? do you have list of those?

Regards
Ankur

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

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

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

Raghu Ram Y
Kilo Sage

@Shikha puri 

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]);
    }

}

Anurag Tripathi
Mega Patron
Mega Patron

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

-Anurag