Need to trigger a notification when all the tasks associated with case closed complete?

Ramu6
Tera Contributor

Hi All,

I have a requirement that , basically when HR case is created , they manually create HR tasks, i want to trigger a notification that it checks all the tasks associated with case as closed complete then the notification will trigger to health group? and that includes body as 

Hi <HR service name>

Please note that the tasks you have requested on <date of tasks submitted> for <Employee Name> have now been marked as complete.

 

Please help to resolve this

 

Thanks

Ramu

2 ACCEPTED SOLUTIONS

@Ramu6 

then do this

1) have notification on HR Task, with your subject, body etc. I hope you know how to do this

Condition as State Changes to Close

2) Use advanced condition in notification and check if this task is the last one; if yes then set answer=true

var gr = new GlideRecord("sn_hr_core_task");
gr.addActiveQuery();
gr.addQuery("parent", current.parent);
gr.setLimit(1);
gr.query();
answer = !gr.hasNext();

AnkurBawiskar_0-1697629607150.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

@Ramu6 

something like this. please enhance

(function runMailScript(current, template, email, email_action, event) {

	// Add your code here

	var gr = new GlideRecord("sn_hr_core_task");
	gr.addQuery("parent", current.parent);
	gr.query();
	while (gr.next()) {
		template.print("Please note that the task you have requested on " + new GlideDateTime(gr.sys_created_on).getDate() + "for " + gr.parent.subject_person.name + " have now been marked as complete.");
	}


})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

@Ramu6 

then do this

1) have notification on HR Task, with your subject, body etc. I hope you know how to do this

Condition as State Changes to Close

2) Use advanced condition in notification and check if this task is the last one; if yes then set answer=true

var gr = new GlideRecord("sn_hr_core_task");
gr.addActiveQuery();
gr.addQuery("parent", current.parent);
gr.setLimit(1);
gr.query();
answer = !gr.hasNext();

AnkurBawiskar_0-1697629607150.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 

Thanks for code, its working fine, but as i mentioned above, in the body i want 

Hi <HR service name>

   Please note that the tasks you have requested on ${date_of_tasks_submitted} for ${employee_name} (subjected person)have now been marked as complete.

 

Like that but i am unable drag these fields on the body using parent case, but here parent means , it shows the main task fields

 

@Ramu6 

Glad to know.

which fields you want to show? notification is on HR task so you can show that fields

you can also dot walk to parent and pick employee name

what's the challenge?

Date of tasks submitted will be different for each task under that HR case and it will be different value. Which one you want to print in email body

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 

I have tried to dot walk from parent field, but it shows the list of parent task field not the parent case.

Basically i want  HR service name and Employee name fields from the parent case in the notification body ?

And also want all the date of submitted for tasks if possible or the last task date submitted ?

@Ramu6 

you should able to print HR Service by dot walking to parent-> HR Service -> name

please share your screenshot of email body

Since you said dates of all tasks then you need to use email script and then use GlideRecord to get all HR Tasks and print it

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader