- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2023 02:38 PM
I have a category and a list of subcategories on our incident table. The category should only be visible if there is a value of true on an external user field. What is the best approach to accomplish this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2023 06:28 PM
HI @Community Alums ,
I trust you are doing great.
Here's a script that will achieve this functionality:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// Assuming the field name of the custom true/false field is 'external_user_field'
// and the internal name of the category field is 'category'
var externalUserValue = g_form.getValue('external_user_field');
if (externalUserValue === 'true') {
g_form.setDisplay('category', true); // Show the category field
} else {
g_form.setDisplay('category', false); // Hide the category field
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2023 11:47 PM
Hi @Community Alums
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2023 02:57 PM
Hi Shannon,
Are you saying that you want the entire category field to only be visible under this condition, or a/certain category choice value(s)? What do you mean by external user field - can you trace this back to a field on a ServiceNow table that has the value of true or false?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2023 03:03 PM
We have added a custom true/false field for external users.
The category should only show if this toggle is true. It should not show in the drop-down if not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2023 04:19 PM
Hi @Shannon Pearson,
You can write an onchange client script for that like,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2023 05:02 PM - edited ‎12-04-2023 07:53 PM
so just to clarify, if external user field = true on the user record, you want to retain the category field on the form - but hide a particular category so it is not available to be selected?
if so you will need to write an onChange client script that interogates the user record and removes the option from the list. Try this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var user = g_form.getReference('caller_id',extUser);
function extUser(user){
if (user.your_field_name == 'true'){
alert("removing category");
g_form.removeOption('category','category value');
} }
}
some notes:
the option is now gone until you reload the page, so if you change back to a user without this value - it will no longer be an option.
if you refresh the page in some way (e.g. form save, reload, etc) it will be available again. I would write an onLoad client script that does the same thing to prevent this. Then the option is gone as long as this user is selected, but if you change the user and hit save - it should come back
if all you want to do is hide the category field, use a UI policy. You dont need a client script. Check the caller related fields for your flag and have it set category visibility = false.