Show a field only when checkbox is selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 03:34 PM - edited 07-13-2023 03:35 PM
Hello experts,
I would like to show a field only when a checkbox is selected. Is there any way to do that?
Below is a screenshot of my request when user requests new asset. I want the new_computer_asset to show only when Desktop or Laptop is checked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 05:39 PM
Hello ,
There are two ways to achieve this -
first is using Catalog UI Policies in ServiceNow. Catalog UI Policies allow you to control the visibility and behavior of form fields in catalog items based on conditions.
also you can write a client script something like this -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Get the checkbox field value
var checkboxValue = g_form.getValue('checkbox_field_name');
// Get the new_computer_asset field element
var newComputerAssetField = g_form.getControl('new_computer_asset');
// Check the checkbox value and show/hide the new_computer_asset field accordingly
if (checkboxValue === 'Desktop' || checkboxValue === 'Laptop') {
g_form.setVisible(newComputerAssetField, true); // Show the field
} else {
g_form.setVisible(newComputerAssetField, false); // Hide the field
}
}
Mark as correct and helpful if it solved your query.
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2023 08:56 PM
Did you try using catalog UI policy?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader