Workflow multi-value Field

Hi everyone,

I need your help with adjusting our workflow. We are using the notify-assignee-on-overdue workflow, which currently has a single-value assignee field. We want to change this field to a multi-value field so that multiple assignees can be added.

My question is: What adjustments need to be made in the workflow so that all assignees receive a notification when a task is overdue?

I look forward to your suggestions and experiences!

I have updated the script with usersToNotify and multi: true. However, I am encountering the following debug messages:

workflow_user_892753348 27 Feb. 2025 10:22
User object:,[{"$$type": " User", "login": "Mr_Test"}]
workflow_user_892753348 27 Feb. 2025 10:22
User notify function not available for:,[{"$$type": " User", "login": "Mr_Test"}]
workflow_user_892753348 27 Feb. 2025 10:22
User details:,{}

Thank you in advance!

Best regards,
Mark

0
2 comments
Official comment

Hi!

I'm Sergey from the YouTrack team.

The default due date workflow only works with the single-value assignee field. Multi-value fields store data in a set. Hence, you should adjust you workflow to use set's properties and methods to access values in a multi-value field. See the example of the updated 'notify-assignee-on-overdue' rule below. 

const entities = require('@jetbrains/youtrack-scripting-api/entities');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');
const dateTime = require('@jetbrains/youtrack-scripting-api/date-time');
exports.rule = entities.Issue.onSchedule({
 title: 'Notify assignees about overdue issues', // Changed "assignee" to "assignees"
 search: '#Unresolved has: {Due Date}',
 cron: '0 0 10 ? * MON-FRI',
 guard: (ctx) => {
   return ctx.issue.fields.DueDate < Date.now();
 },
 action: (ctx) => {
   const issue = ctx.issue;
   const assignees = issue.fields.Assignee; // Changed single user to a Set
   const formattedDate = dateTime.format(issue.fields.DueDate);
   const notificationText = workflow.i18n('Issue became overdue on <i>{0}</i>:', formattedDate) +
           ' <a href="' + issue.url + '">' + issue.summary + '</a><p style="color: gray;font-size: 12px;margin-top: 1em;border-top: 1px solid #D4D5D6">' +
           workflow.i18n('Sincerely yours, YouTrack') + '</p>';
   if (assignees && assignees.isNotEmpty()) { 
     assignees.forEach(user => { // Iterate over Set
       user.notify(workflow.i18n('[YouTrack, Issue is overdue]'), notificationText);
     });
   } else if (issue.project.leader) {
     issue.project.leader.notify(workflow.i18n('[YouTrack, Issue is overdue]'), notificationText);
   }
 },
 requirements: {
   DueDate: {
     type: entities.Field.dateType,
     name: 'Due Date'
   },
   Assignee: {
     type: entities.User.fieldType,
     multi: true // Define Assignee as a multi-value field
   }
 }
});

Please sign in to leave a comment.