- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 06:08 AM
Hi
I want a task to be done. I want to close my problem record if only all the problem tasks are closed. Otherwise an error message has to be displayed. How to configure this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 06:10 AM
Hi @NishaB
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 06:11 AM
Hello @NishaB
Create a before business rule on problem table:
(function executeRule(current, previous /*null when async*/) {
var problemTasks = new GlideRecord('problem_task');
problemTasks.addQuery('problem', current.sys_id);
problemTasks.addQuery('state', '!=', '3');
problemTasks.query();
if (problemTasks.hasNext()) {
gs.addErrorMessage("Cannot close the problem record because not all problem tasks are closed.");
current.setAbortAction(true); // Prevents the record from being saved
}
})(current, previous);
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 06:13 AM
Hello @NishaB
Create a "Before Update" BR - with condition as state "changes to" "closed" and add below 👇 script
// Trigger only if state is changing to 'Closed'
if (current.state.changesTo('Closed')) {
// Check for any open Problem Tasks
var taskGR = new GlideRecord('problem_task');
taskGR.addQuery('problem_id', current.sys_id);
taskGR.addQuery('state', '!=', 'Closed');
taskGR.query();
if (taskGR.hasNext()) {
gs.addErrorMessage('Cannot close the Problem record because one or more Problem Tasks are still open.');
current.setAbortAction(true
);
}
}
Make changes as per your field names.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 06:56 AM
you can use before update business rule on problem table and use GlideAggregate to optimize rather than using getRowCount()
Condition: State Changes to Closed/Resolved
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Use GlideAggregate to count problem tasks that are not closed
var agg = new GlideAggregate('problem_task');
agg.addQuery('problem', current.problem); // Filter by the current problem record
agg.addEncodedQuery('stateNOT IN3,4,7'); // Count tasks that are not closed
agg.addAggregate('COUNT'); // Aggregate the count of matching records
agg.query();
if (agg.next() && parseInt(agg.getAggregate('COUNT')) > 0) {
// If there are any open problem tasks, display an error message
gs.addErrorMessage('Cannot close the problem record because there are open problem tasks.');
current.setAbortAction(true); // Prevent the problem record from being closed
}
})(current, previous);
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-15-2025 12:39 AM
Hope you are doing good.
Did my reply answer your question?
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well 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-07-2025 06:56 AM
you can use before update business rule on problem table and use GlideAggregate to optimize rather than using getRowCount()
Condition: State Changes to Closed/Resolved
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Use GlideAggregate to count problem tasks that are not closed
var agg = new GlideAggregate('problem_task');
agg.addQuery('problem', current.problem); // Filter by the current problem record
agg.addEncodedQuery('stateNOT IN3,4,7'); // Count tasks that are not closed
agg.addAggregate('COUNT'); // Aggregate the count of matching records
agg.query();
if (agg.next() && parseInt(agg.getAggregate('COUNT')) > 0) {
// If there are any open problem tasks, display an error message
gs.addErrorMessage('Cannot close the problem record because there are open problem tasks.');
current.setAbortAction(true); // Prevent the problem record from being closed
}
})(current, previous);
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-15-2025 12:39 AM
Hope you are doing good.
Did my reply answer your question?
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader