Workflow Help - Creating a Reminder Email Workflow

I am currently working on creating a wokflow that sends a Reminder Email once a specific date is set in a custom date field.  I am getting the following error when I attempt to save the workflow:

Parsing or evaluation exception:  Error while loading script for rule reminderemail: Rule's 'search' is undefined

Below is the script I have written, but I am unsure what is causing the issue.  Any help is appreciated.

Thanks!

 

var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');

exports.rule = entities.Issue.onSchedule({
title: 'ReminderEmail',
cron: '0 0 8 * * MON-FRI',
guard: function(ctx) {
return ctx.issue.fields.ReminderDate == Date.now() && ctx.issue.fields.Assignee;
},
action: function(ctx) {
var getLinkToIssue = function(i) {
return '<a href="' + i.url + '">' + i.id + '</a> ' + '<a href="' + i.url + '">' + i.summary + '</a>';
};

var issue = ctx.issue;
var subject = workflow.i18n('Follow-up Reminder on {0}', issue.id);
var body = workflow.i18n('Please review the comments section for notes on the reason for follow-up to assist in resolving {0}', getLinkToIssue(issue));

ctx.Assignee.notify(subject, body, true);
},
requirements: {
State: {
type: entities.State.fieldType,
ReminderDate: {
name: 'Reminder Date'
}
},
Assignee: {
type: entities.User.fieldType
}
}
});

4 comments
Comment actions Permalink
Official comment

Hi Ken,

The error tells you that you have not set a `search` property for the on-schedule rule (other properties are `title`, `cron` etc). `search` property defines which issues have to be processed by this rule. By default (in template) it looks like

search: '#Unresolved'

In your particular case I would suggest the following search (as narrow as possible):

search: '#Unresolved has: {Reminder Date} has: Assignee'

Also, I would recommend a couple of changes:

1. You do not need 'workflow.i18n' function when writing own workflows (because you always know the language of your own instance and do not have tools to add new like in localization files anyway)

2. You should use 'issue.fields.Assignee' instead of 'ctx.Assignee' (as the latter is a field instance, while the former is the field value).

Comment actions Permalink

Thanks Mariya!

So if I am understanding correctly then on #2 then it should look like this?

issue.fields.Assignee.notify(subject, body, true);

0
Comment actions Permalink

Ken,

Yes, that's right.

0
Comment actions Permalink

Fantastic!  Thank you so much!

0

Please sign in to leave a comment.