- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 11:14 AM
On change Catalog item
variables string filed like : Field1 ,field11,filed2,field22,filed3,field33 there are six string filed .
and choice field : name : select value
choice value : none,0,1,2,3.
Scenario :
1.When i select none and 0 no one filed populate all the field need to hide .
2. Then If i selected choice value 1 the Field 1 and field11 this field need to visible and need to set mandatory rest of the fields need to Hide .
3.Then if i select choice value 2 then Field1 , field11 and filed2 , field22 these four field need to visible and set mandatory rest of the fields need to Hide .
4.Then if i select choice value 3 then Field1 , field11 and filed2 , field22 , field3 , field33 these six field need to visible and set mandatory for six field .
and main thing is these conditions are need to apply task view as well.
Note : if on change is not good practice the suggest any other method to archive this .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 08:23 PM - edited 04-23-2025 08:34 PM
Hi @rajeshraji1
Create Catalog UI policies as below.
1. When Choice value is 1 or 2 or 3: In the Catalog UI policy action, add Field 1 and Field 11 (Make mandatory and Visible as true)
2. When Choice value is 2 or 3:In the Catalog UI policy action, add Field 2 and Field 22 (Make mandatory and Visible as true)
3. When choice value is 3: In the Catalog UI policy action, add Field 3 amd Field 33 (Make mandatory and Visible as true)
Sample UI policy:
In the Catalog UI policies check the below highlighted check boxes.
Hope this helps.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 08:23 PM - edited 04-23-2025 08:34 PM
Hi @rajeshraji1
Create Catalog UI policies as below.
1. When Choice value is 1 or 2 or 3: In the Catalog UI policy action, add Field 1 and Field 11 (Make mandatory and Visible as true)
2. When Choice value is 2 or 3:In the Catalog UI policy action, add Field 2 and Field 22 (Make mandatory and Visible as true)
3. When choice value is 3: In the Catalog UI policy action, add Field 3 amd Field 33 (Make mandatory and Visible as true)
Sample UI policy:
In the Catalog UI policies check the below highlighted check boxes.
Hope this helps.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 10:04 PM
HI @J Siva This method is not working i have tried when i apply all this conditions isn't behave correctly kindly suggest i have mentioned on change script so kindly review it and propose solution .this on change script not working in task view also i have selected all the view form option. and global icon also checked
if i select 0 to 1 and 1 to 2 its working fine when i select 2 to none functions not working .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 10:26 PM
you can use onChange catalog client script which applies to Catalog Task as well
something like this, please enhance
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Define the fields
var fields = ['field1', 'field11', 'field2', 'field22', 'field3', 'field33'];
// Hide all fields initially
fields.forEach(function(field) {
g_form.setDisplay(field, false);
g_form.setMandatory(field, false);
});
// Show and set mandatory based on the selected value
switch (newValue) {
case '1':
g_form.setDisplay('field1', true);
g_form.setDisplay('field11', true);
g_form.setMandatory('field1', true);
g_form.setMandatory('field11', true);
break;
case '2':
g_form.setDisplay('field1', true);
g_form.setDisplay('field11', true);
g_form.setDisplay('field2', true);
g_form.setDisplay('field22', true);
g_form.setMandatory('field1', true);
g_form.setMandatory('field11', true);
g_form.setMandatory('field2', true);
g_form.setMandatory('field22', true);
break;
case '3':
g_form.setDisplay('field1', true);
g_form.setDisplay('field11', true);
g_form.setDisplay('field2', true);
g_form.setDisplay('field22', true);
g_form.setDisplay('field3', true);
g_form.setDisplay('field33', true);
g_form.setMandatory('field1', true);
g_form.setMandatory('field11', true);
g_form.setMandatory('field2', true);
g_form.setMandatory('field22', true);
g_form.setMandatory('field3', true);
g_form.setMandatory('field33', true);
break;
default:
// 'none' or '0' case
break;
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2025 02:38 AM
as you mentioned code is not working as expected when we select the value vise versa its behave different.
you have any UI policy suggestion ?