var entities = require('@jetbrains/youtrack-scripting-api/entities');
var notifications = require('@jetbrains/youtrack-scripting-api/notifications');
exports.rule = entities.Issue.onChange({
title: 'Send Email Notification',
guard: function(ctx) {
return true;
},
action: function(ctx) {
var issue = ctx.issue;
var recipients = ['example@test.de'];
var emailTemplate = '<html><body>' +
'<p>Issue {{issue.id}} wurde aktualisiert.</p>' +
'<p>Zusammenfassung: {{issue.summary}}</p>' +
'<p>Status: {{issue.State.name}}</p>' +
'</body></html>';
var email = notifications.email({
to: recipients,
subject: 'Aktualisierung von Issue ' + issue.id,
body: emailTemplate
});
notifications.send(email);
}
});
I try to send an email to the creator of the ticket with the content of the comment when a comment has been added to the ticket. However, I always get the error message TypeError: notifications.email is not a function or Message contains an undefined list of recipient email addresses or the list is empty. What did I wrong?
It should be notifications.sendEmail(). Here is an example you can refer to:
var issue = ctx.issue;
if (issue.comments.added.isNotEmpty()) {
var authorName = issue.comments.added.first().author.fullName;
var message = {
fromName: authorName,
to: ['user1@jetbrains.com', 'user2@jetbrains.com'],
cc: ['user1@jetbrains.com', 'user2@jetbrains.com'],
bcc: ['user1@jetbrains.com', 'user2@jetbrains.com'],
subject: 'New comment in ' + issue.id,
headers: {
'X-Custom-Header': 'Important value'
},
body: [
'<div style="font-family: sans-serif">',
' <div style="padding: 10px 10px; font-size: 13px; border-bottom: 1px solid #D4D5D6;">',
' New comment was added in issue ' + issue.id + ' by ' + authorName,
' </div>',
'<\div>'
].join('\n')
};
notifications.sendEmail(message, issue);
}
Also, here is the corresponding documentation: https://www.jetbrains.com/help/youtrack/devportal/v1-notifications.html#functions