- 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
‎01-07-2022 12:36 AM
Hi
Thanks for the code, this code is helpful to me as well, but I got a small issue that is I wrote this code based on this Change type so when value is changed from Normal to any other value all the field values will be cleared its working fine, but when change type is changes to other value directly its going to bottom of the form or page everytime... do you know anything about it..
Thanks.