onChange Catalog Client Script to Clear Values for Reference, Choice and List Collector Fields

chatsaurav19
Tera Contributor

Hi All,

 

I need to remove values from two reference fields, one choice field and one List Collector field based on a choice field selection.

 

Type of Request : Choice List ( On selection of this field, the below field values needs to be cleared )

 

Knowledge Base : Reference

Categories : Reference

Role: Choice

Manage Acess: List Collector

 

chatsaurav19_0-1694670932241.png

 

 

I tried using 'OnChange' Catalog Client Script but it isn't working:::

 

function onChange(control, oldValue, newValue, isLoading) {
// if (isLoading || newValue == '') {
// return;
// }

//Type appropriate comment here, and begin script below
if (isLoading) {
return;
}
if (newValue == "") {
g_form.clearValue('knowledge_base_kb');
g_form.clearValue('categories_kb');
g_form.clearValue('role_kb');
g_form.clearValue('manage_acess_kb');
}
}

 

Can someone help me in this?

 

Regards,

Saurabh Chatterjee

 

1 ACCEPTED SOLUTION

Can you check if Ui type is selected ALL & Variable name

 

VishalBirajdar7_1-1694672092615.png

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

8 REPLIES 8

Vishal Birajdar
Giga Sage

Hi @chatsaurav19 

 

Can you try below...!!

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
g_form.clearValue('knowledge_base_kb');
g_form.clearValue('categories_kb');
g_form.clearValue('role_kb');
g_form.clearValue('manage_acess_kb');

}
Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hi @Vishal Birajdar ,

 

It didn't work.

 

Regards,

Saurabh

Can you check if Ui type is selected ALL & Variable name

 

VishalBirajdar7_1-1694672092615.png

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Ankur Bawiskar
Tera Patron
Tera Patron

@chatsaurav19 

are you sure the newValue is empty?

Did you add alert and check?

function onChange(control, oldValue, newValue, isLoading) {

//Type appropriate comment here, and begin script below
if (isLoading) {
return;
}

alert(newValue);

if (newValue == "") {
g_form.clearValue('knowledge_base_kb');
g_form.clearValue('categories_kb');
g_form.clearValue('role_kb');
g_form.clearValue('manage_acess_kb');
}
}

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