New field to count open tickets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 05:19 AM
I need to create a a new field to count open incident tickets,. this field should assign every ticket the number 1 in the new field "Open count" when the ticket is open, then when the ticket is closed or set to closed complete the ticket will automatically set the field "Open count" to 0. what best option should be used for this
I know a UI policy can be created to make this field dynamic for the state field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 08:25 AM
Hi Joyea,
Can you explain the requirement or business ask here please?
Following best practice and using already available fields, in order to perform a count and report on ‘Open’ and ‘Closed’ tickets you can leverage the ‘Active’ field. This is a boolean value or either ‘true’ or ‘false’.
When a ticket is open and passes through the ticket lifecycle until it is closed – it will remain ‘Active’ (active will be set to true).
When the ticket is closed, the active flag will be set to false.
You can perform all sorts of reports and list counts etc using the active flag to obtain the functionality you describe without creating a new field for this.
Please expand, or if I have answered your question correctly – please mark my response correct and/or helpful.
Thanks,
Robbie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 09:02 AM
Hello @DevtoSME ,
If you want to set the "Open count" field to 1 if the incident is open (incident_state is 1), and 0 if the incident is closed. You can go with the below solution. I would prefer to rethink on @Robbie 's suggestion before jumping on this 🙂
You can achieve this requirement by using a Business Rule.
- Navigate to "System Definition" > "Business Rules" in ServiceNow.
- Click on "New" to create a new Business Rule.
- Give the Business Rule a name, such as "Update Open Count," and set the table to "Incident" since you want to apply this logic to incident records.
- In the "When to run" section, select the appropriate conditions for when the Business Rule should run. For this case, you want the Business Rule to run when the incident record is inserted, and updated, or when the incident 'state' field is changed.
- In the "Advanced" section, enter the following script:
(function executeRule(current, previous /*null when async*/ ) {
// Check if the incident is open
if (current.incident_state == '1') { // Assuming '1' is the code for 'Open' state
current.open_count = 1; // Set the "Open count" field to 1
} else if(current.incident_state == '7'){
current.open_count = 0; // Set the "Open count" field to 0 for any other state
}
})(current, previous);
If this helped you in any way, please hit the like button/mark it helpful. Also, don't forget to accept it as a solution. So it will help others to get the correct solution.
thanks,
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 09:47 AM - edited 07-26-2023 09:51 AM
Hi @Joyea Mells,
Whilst I appreciate @Community Alums has tried to provide a solution (and has also steered you back to my initial response - Thanks @Community Alums), I really would not implement the script provided.
(There are many states to cater for eg New, In Progress, On Hold etc, there is no 'open_count' field on the 'incident' table - however there is on the 'incident_fact_table' table to name a few reasons)
Perhaps you can provide us both with some clarification on what the requirement is and why you need this field?
I do however believe you can get everything you need (based on your question) from the 'Active' field.
To help others, please mark my answer as correct and/or helpful.
Thanks,
Robbie