- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2020 08:08 AM
Hi all,
I have a catalog item which has 10 different categories. Each category has a UI policy in place which displays different fields based on category.
I want to clear all variable values when the category changes. I tried using the 'clear variable value' option within UI policy action but that caused issues for me and ServiceNow have said to not use that option and use a client script instead.
I found an onchange client script on the community article and tried using that but it is causing the fields to not show up at all now.
When I am selecting a category, none of the fields are displaying.
Please can you advise on this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2020 08:24 AM
try
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldArr = ['request_type', 'item_to_return_label', 'business_justification', 'select_item', 'return_address_label', 'address_line_1', 'return_address2', 'address_line_2', 'city', 'post_code', 'formatter', 'state_province', 'country', 'formatter2', 'please_provide_any_additional_details', 'justification', 'request_type_website', 'website_address', 'additional_details_website', 'justification_website', 'request_type_software', 'software_application', 'request_details_software', 'justification_software', 'request_type_security', 'request_details_security', 'request_details_helpadvice', 'request_type_useraccounts', 'software_application_useraccounts', 'request_details_useraccounts', 'business_justification_useraccounts', 'address_request', 'address_line_1_request', 'address_line_2_request', 'city_request', 'post_code_request', 'formatter3', 'state_province_request', 'country_request']; //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
‎11-06-2020 08:11 AM
Field Array needs to belike below (each value with quotes separated by comma)
var fieldArr = ['request_type', 'item_to_return_label', 'XXXXXX'];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2020 08:20 AM
Hi Mike,
I changed the field array as you suggested, but still getting the same issue.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldArr=['request_type','item_to_return_label','business_justification','select_item','return_address_label','address_line_1','return_address2','address_line_2','city','post_code','formatter','state_province','country','formatter2','please_provide_any_additional_details','justification','request_type_website','website_address','additional_details_website','justification_website','request_type_software','software_application','request_details_software','justification_software','request_type_security','request_details_security','request_details_helpadvice','request_type_useraccounts','software_application_useraccounts','request_details_useraccounts','business_justification_useraccounts','address_request','address_line_1_request','address_line_2_request','city_request','post_code_request','formatter3','state_province_request','country_request']; //add comma separated field names which you want to clear here
for(var field in fieldArr){
g_form.clearValue(fieldArr[field]);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2020 08:24 AM
try
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var fieldArr = ['request_type', 'item_to_return_label', 'business_justification', 'select_item', 'return_address_label', 'address_line_1', 'return_address2', 'address_line_2', 'city', 'post_code', 'formatter', 'state_province', 'country', 'formatter2', 'please_provide_any_additional_details', 'justification', 'request_type_website', 'website_address', 'additional_details_website', 'justification_website', 'request_type_software', 'software_application', 'request_details_software', 'justification_software', 'request_type_security', 'request_details_security', 'request_details_helpadvice', 'request_type_useraccounts', 'software_application_useraccounts', 'request_details_useraccounts', 'business_justification_useraccounts', 'address_request', 'address_line_1_request', 'address_line_2_request', 'city_request', 'post_code_request', 'formatter3', 'state_province_request', 'country_request']; //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
‎11-06-2020 08:38 AM
Thanks Mike this has worked!