- Stefan Hulls
ITRP monitor+ mail subscription package

Prerequisites:
You already have an ITPR demo account or a production account. If not, you can easily request one with demo data.
You already signed up for a techwork automator demo account. If not, goto the registration blog post.
You already configured the ITRP monitor+ in your demo environment. If not, goto the ITRP monitor+ blog post.
Business case:
ITRP currently does not provide a function to send out updates on a request to a person who is not involved at all. However, sometimes C-level managers want to be updated on any changes of major incidents/requests because of its significance. The package below sends out an email to every subscriber. The beauty of the implementation is that the package does not send out an email if subscribers changes.
$request = request;
mergeAudit($request);
$sOld = $request.audit_old_custom_data.monitor_subscribers;
$sNew = $request.audit_new_custom_data.monitor_subscribers;
$mailData = createTemplateHTMLMail('request-watch-all-notes');
if ($sNew && $sOld === $sNew) {
for($item of $sNew) {
$mailData.to = $item;
sendMail($mailData);
}
}
The email the subscriber gets

The code with comments
$request = request;
mergeAudit($request);
//check who is in the custom data field
//the old value(s) and the updated one(s)
$sOld = $request.audit_old_custom_data.monitor_subscribers;
$sNew = $request.audit_new_custom_data.monitor_subscribers;
$mailData = createTemplateHTMLMail('request-watch-all-notes');
//if new is equal to old then the mail(s) are sent
//
//the line below prevents sending out an email if someone
//subscribes or unsubscribes
if ($sNew && $sOld === $sNew) {
foreach($sNew) {
$mailData.to = $item;
sendMail($mailData);
}
}
Interesting to note
The mail is not sent, if someone subscribes or unsubscribes even though it is an update of the request. To get that done the “mergeAudit” function is of great help. This function merges audit information into an ITRP object. In our particular case it allows to send the email if anything changes except changes within the monitor_subscribers custom data field.