Incident can be changed to resolved only, when all associated incident tasks are closed.-- Through workflow only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2019 06:10 AM
Hi all,
I have created a workflow for creating and updating an incident ticket. I have created "incident task" through inbound mail.
when all "incident task" state changes to complete then only "incident" state changes to "Resolve or complete" which is automatically.
I need to this in only workflow. can one help me out of this.
I am uploading screenshots of the workflow and script.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2019 04:36 PM
You can't achieve this using a workflow. Because workflow only runs when a record is updated.
You need a Business rule where you need to write the above code you posted. It should be an onUpdate Before business rule.
Ans in the workflow wait for condition, just check, if state is changed to closed. You wont need Set Value after that. Just end it.
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2019 05:47 PM
There a few ways this can be implemented, it can be achieved with a combination of Business Rules & Workflow, or Business Rules alone. The later is probably a simpler solution - but I have provided the former solution as you requested.
- Replace your "Wait for condition - tasks closed" with "Wait For Workflow Event" Activity
- Set the event to Wait for as 'close'
- Create an After Business Rule on Incident Task with the condition 'Status' Changes to "Closed"
// This code is not tested - example only if (getNumOfActiveIncidentTasks() == 0) { broadcastCloseIncident(); } function broadcastCloseIncident() { var parent = current.parent.getRefRecord(); //Assuming parent only has one workflow //Assuming incident is in parent field var wf = new Workflow().getRunningFlows(parent); if(wf.next()) { new Workflow().broadcastEvent(wf.sys_id, 'close'); } } function getNumOfActiveIncidentTasks() { var activeIncidentTasks = 0; var grIncidentTask = new GlideAgrregate('incident_task'); grIncidentTask.addActiveQuery(); //Assuming incident is in parent field grIncidentTask.addQuery('parent',current.parent); grIncidentTask.addAggregate('COUNT'); grIncidentTask.query(); while(grIncidentTask.next()) { activeIncidentTasks = grIncidentTask.getAggregate('COUNT'); } //Sometimes getAggregate returns a string return parseInt(activeIncidentTasks); }
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2019 07:00 PM
try this...use hasNext()
var incTask = new GlideRecord("incident_task");
incTask.addQuery("parent",current.sys_id);
incTask.addQuery("state", "!=", 3);
incTask.query();
if(incTask.hasNext())
{
gs.addErrorMessage('You can't close an incident with active tasks');
current.setAbortAction(true);
}
Harish