# Rule to send email notification whenever aggregation and refresh tasks fails

**URL:** <https://developer.sailpoint.com/discuss/t/rule-to-send-email-notification-whenever-aggregation-and-refresh-tasks-fails/80548>\
**Category:** IIQ Discussion and Questions\
**Tags:** rules, identityiq, aggregation\
**Created:** [September 9, 2024, 2:20pm UTC](https://developer.sailpoint.com/discuss/t/rule-to-send-email-notification-whenever-aggregation-and-refresh-tasks-fails/80548 "2024-09-09T14:20:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemant\_agrwl](https://avatars.discourse-cdn.com/v4/letter/h/9fc29f/32.png) [@hemant\_agrwl](https://developer.sailpoint.com/discuss/u/hemant_agrwl)\
**Post date:** [September 9, 2024, 2:20pm UTC](https://developer.sailpoint.com/discuss/t/rule-to-send-email-notification-whenever-aggregation-and-refresh-tasks-fails/80548/1 "2024-09-09T14:20:11Z")

</div>

## Which IIQ version are you inquiring about?

8.4

## Share all details about your problem, including any error messages you may have received.

We have many HRMS applications for which aggregation tasks run on scheduled basis.  
The requirement is to get email notification whenever aggregation and refresh tasks fails but we dont want to use the inbuilt notification functionality for tasks.  
We want to do it via runrule task, so can anyone help me with the coding part of it.

---

<div class="post-metadata">

**Author:** ![ajmerasunny1](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@ajmerasunny1](https://developer.sailpoint.com/discuss/u/ajmerasunny1)\
**Post date:** [September 9, 2024, 6:16pm UTC](https://developer.sailpoint.com/discuss/t/rule-to-send-email-notification-whenever-aggregation-and-refresh-tasks-fails/80548/2 "2024-09-09T18:16:50Z")

</div>

I don’t have a sample rule, but I can guide you with the logic or provide pointers based on how I’ve handled it in the past. I created a rule where I monitored a list of task definitions for failures or overruns. Using the task results, I checked their completion time and status, then built the logic to trigger an email notification accordingly.

---

<div class="post-metadata">

**Author:** ![phodgdon](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/phodgdon/32/3452_2.png) [@phodgdon](https://developer.sailpoint.com/discuss/u/phodgdon)\
**Post date:** [September 13, 2024, 1:02am UTC](https://developer.sailpoint.com/discuss/t/rule-to-send-email-notification-whenever-aggregation-and-refresh-tasks-fails/80548/3 "2024-09-13T01:02:29Z")

</div>

I’ve built a plugin before that uses a service definition to check for certain task failures and if the last task status failed it sent an SMS message to the admins. It would just log that it notified them so it wouldn’t keep sending messages when the service ran every 90 seconds or so.

---

<div class="post-metadata">

**Author:** ![ashutosh08](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ashutosh08/32/11459_2.png) [@ashutosh08](https://developer.sailpoint.com/discuss/u/ashutosh08)\
**Post date:** [September 13, 2024, 5:29am UTC](https://developer.sailpoint.com/discuss/t/rule-to-send-email-notification-whenever-aggregation-and-refresh-tasks-fails/80548/4 "2024-09-13T05:29:15Z")

</div>

Hi @hemant_agrwl,

You can try below snippet to trigger mail notification. If you are able to filter out the failed task, then you can use below snippet to send notification.

```auto
EmailTemplate template=context.getObjectByName(EmailTemplate.class,"");
		EmailOptions opt=new EmailOptions();
		opt.setTo("abc@mail.com");
		opt.setVariable("identityName","Some Name");
		context.sendEmailNotification(template, opt);

```

Let me know if further input is needed.

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [November 12, 2024, 5:29am UTC](https://developer.sailpoint.com/discuss/t/rule-to-send-email-notification-whenever-aggregation-and-refresh-tasks-fails/80548/5 "2024-11-12T05:29:57Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
