Hide Choices based on field value in List View in Workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi Everyone,
I need some help with hiding/restricting specific choices in a field.
I have a Type field on the Exception table with two choices: Open and Closed. I also have a Status field with four choices: 1, 2, 3, and 4.
My requirement is that when Type = Open, the Status choices 1 and 2 should not be visible or selectable for the user. Only the other Status choices should be available.
There is a list configured in Workspace where users can see the Exception records, and they need to update the Status field using inline/cell edit from the list.
I tried implementing this using a on Cell edit Client Script, but it is not working as expected, and I am unable to hide the specific Status choices from the dropdown during inline editing.
Has anyone implemented a similar requirement in ServiceNow on cell edit script What would be the recommended approach to hide or restrict specific choice values based on another field's value?
Any guidance or examples would be greatly appreciated.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@harinya
You don't need an onCellEdit script for this requirement. Since Status is a Choice field and its available values depend on Type, I would use a Dependent Choice configuration.
In your case:
Type
Open
Closed
Status
- 1
- 2
- 3
- 4
Configure Status as dependent on Type: Open the Status dictionary record. Under Dependent field, select Use dependent field. Set the dependent field to Type. Open Configure Choices for Status.
For Status choices 1 and 2, set the Dependent value to the value of Type that represents Closed.
Leave the dependent value appropriately configured for 3 and 4 so that they remain available for the required Type values.
The result would be:
Type = Open → Status: 3, 4
Type = Closed → Status: 1, 2, 3, 4
This is preferable to manipulating the choice list through an onCellEdit script because the dependency is part of the field configuration and can be used to control the available choices based on another field. ServiceNow specifically supports dependent Choice fields for limiting the values available based on another field.
https://www.servicenow.com/docs/r/platform-administration/t_MakingAFieldDependent.html
Also, onCellEdit is intended to run when the list editor changes a cell, rather than being a mechanism for dynamically controlling which options are displayed in the choice dropdown. For validation, onCellEdit can still be useful—for example, to prevent an invalid combination from being saved—but I wouldn't use it as the primary mechanism for hiding the choices.
https://www.servicenow.com/docs/r/zurich/api-reference/scripts/client-scripts.html
One additional recommendation: add a server-side validation (Business Rule/Data Policy as appropriate) if this combination must never be allowed, because client-side filtering should not be relied upon as the only enforcement mechanism.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @harinya ,
Please refer this thread it will help you :
https://www.servicenow.com/community/developer-forum/hide-choice-value-on-list-view/m-p/1397976
If this helps you then mark it as helpful and accept as solution.
Regards,
Aditya
