problem should not resolve if associated ptask is open
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I want to create business rule like if the problem associated Ptask is not resolved then problem should not be resolved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @ashimghosh1
Try This:
Name : Restrict Problem Resolution with Open Tasks
Table: Problem [problem]
Advanced : Checked
When :Before
Update : Checked
(function executeRule(current, previous /*null when async*/) {
var taskGR = new GlideRecord('problem_task');
taskGR.addQuery('problem', current.getUniqueValue());
taskGR.addActiveQuery();
taskGR.setLimit(1 );
taskGR.query();
if (taskGR.next()) {
gs.addErrorMessage('Cannot resolve this Problem because one or more associated Problem Tasks are still open.');
current.setAbortAction(true);
}
})(current, previous);
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ashimghosh1 ,
You'll need a before-update business rule on the problem table.
(function executeRule(current, previous) {
// Only check when status is changing to resolved (6)
if (current.status == '6' && previous.status != '6') {
// Query for any child problems/ptasks that are still open
var gr = new GlideRecord('problem');
gr.addQuery('parent', current.sys_id);
gr.addQuery('status', '!=', '6');
gr.query();
if (gr.getRowCount() > 0) {
gs.addErrorMessage('Cannot resolve. You have ' + gr.getRowCount() + ' open subtask(s) that need to be resolved first.');
current.setAbortAction(true);
}
}
})(current, previous);
'6' usually means "Resolved" but verify that in your instance.
If you found my solution helpful, please mark it as Helpful and Accept Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The field is 'state', not 'status', or 'active'. And OOB values are 106: "Resolved", 107: "Closed".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @ashimghosh1 , Could you please try the below approach and share the feedback?
- Configure the BR as below:
- Under the Advanced tab, use the below script:
(function executeRule(current, previous) {
var openTasks = new GlideRecord('problem_task');
openTasks.addQuery('problem', current.getUniqueValue());
openTasks.addQuery('state', '!=', '157');
openTasks.query();
if (openTasks.hasNext()) {
var count = 0;
while (openTasks.next()) {
count++;
}
gs.addErrorMessage('Cannot close this Problem. There are ' + count + ' associated Problem Task(s) that are not yet closed.');
current.setAbortAction(true);
}
})(current, previous);
Regards,
Nishant