Show a field only when checkbox is selected

Jiajie Li
Tera Contributor

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. 

 

Capture.PNG

2 REPLIES 2

Tushar
Kilo Sage
Kilo Sage

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Jiajie Li 

Did you try using catalog UI policy?

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