YouTrack および Hub ヘルプの開発者ポータル

スケジュール規則

on-schedule ルールは、設定されたスケジュールに従って適用される一連の変更を定義します。例: 特定の属性値に関する課題を定期的にチェックし、ユーザーまたはグループに通知することができます。これらのルールは、以前のワークフローで使用されていたスケジュール済みルールを置き換えます。

スケジュール通りのルールは、特別なワークフローユーザーによって実行されます。これは、すべての権限が付与されたシステムユーザーアカウントです。このアカウントの権限は変更できません。ワークフローユーザーアカウントはライセンス制限に含まれず、ユーザーリストに表示されません。

サンプルスケジュールルール

この規則は毎日 10:00 で実行されます。このルールは、期限日フィールドに値が割り当てられている未解決の課題をチェックします。期日が過ぎている場合は、通知が担当者に送信されます。

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 assignee about overdue issues', 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; let userToNotify = issue.fields.Assignee; if (!userToNotify) { userToNotify = issue.project.leader; } const formattedDate = dateTime.format(issue.fields.DueDate); const notificationText = '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">' + 'Sincerely yours, YouTrack' + '</p>'; userToNotify.notify('[YouTrack, Issue is overdue]', notificationText); }, requirements: { DueDate: { type: entities.Field.dateType, name: "Due Date" }, Assignee: { type: entities.User.fieldType } } });

このスケジュールどおりの規則を定義するコンポーネントは次のとおりです。

  • ここでも、スクリプトは、ワークフロー API の entities モジュールを参照する require ステートメントで始まります。これは、このモジュールに含まれるすべてのものに、このスクリプトで entities 変数を使用してアクセスできることを意味します。

  • この規則では、exports.rule プロパティは Issue.onSchedule メソッドを使用します。これは、宣言に続くスクリプトをスケジュールどおりのルールとしてエクスポートします。

  • ルール本体には、次のプロパティの定義が含まれています。

プロパティ

説明

タイトル

人間が読めるオプションのタイトル。タイトルは管理インターフェースにのみ表示されます。

サーチ

このルールによって処理される課題を決定する検索クエリ。標準の YouTrack 検索クエリ(検索とコマンドの属性を参照)の構文を使用する文字列、またはルールがトリガーされるたびに検索文字列を再計算する関数を使用できます。

関数を使用するときは、名前で参照します。例: search: getSearchExpression

アクション内に条件を追加するのではなく、検索式をできるだけ具体的にすることを強くお勧めします。

クーロン

ルールを適用するスケジュール。Java クーロン式(英語)として指定します。

この例では、式は、YouTrack サーバーに設定されているタイムゾーンの 10:00 で毎日このルールをトリガーします。

期限日フィールドには、日付と時刻が 12:00 UTC として格納されます。たとえば、オフィスがカリフォルニア (UTC-7) にあり、2 日以内に期限が到来するすべての課題についてユーザーに通知したい場合は、期限日を 7 時間ずらす必要があります。詳細については、日付と時刻を操作するを参照してください。

muteUpdateNotifications

このルールによって適用される変更に対して更新通知を送信するかどうかを決定するフラグ。通知を送信せずにアップデートを適用する場合は、true に設定します。

true の場合、このプロパティは、同じトランザクションで適用されるカスケード変更の通知も抑制します。例: オンスケジュールルールによって適用される更新が 1 つ以上のオンチェンジルールからの更新をトリガーする場合、通知を送信せずに変更のセット全体が適用されます。

この例で使用される .notify メソッドのように、このプロパティの値は明示的に送信される通知には影響しません。

ルールは課題の変更を適用しないため、このプロパティはこの例には関係ありません。true に設定されていた場合でも、.notify メソッドを使用して送信されるメール通知は引き続き配信されます。

更新されたプロパティを変更する

このルールによって適用される変更によって課題の updated および updated by プロパティの値が更新されるかどうかを決定するフラグ。これらのプロパティを更新する場合は、このフラグを true に設定します。

2023.1 から利用可能

ガード

ルールを実行するための条件を決定する機能。保護条件が満たされていない場合、ルールに指定されているアクションは課題に適用されません。

アクション

検索条件に一致する各課題に適用されるアクション。このアクションは、課題ごとに個別にトリガーされます。アクション自体は、ワークフローユーザーアカウントによって実行されます。

この例では、Assignee.notify メソッドを使用して、課題が期限切れであることを現在の担当者に警告します。

要件

ルールがエラーなしで実行されるために必要なエンティティのリスト。このプロパティにより、ルールをプロジェクトに安全にアタッチできるようになります。

この例では、要件により、担当者フィールドと期限日フィールドの両方に正しいタイプが格納され、ルールが関連付けられているプロジェクトで使用できることが保証されます。いずれかのフィールドが存在しない場合、ワークフローリストにエラーが表示されます。必須フィールドがアタッチされるまで、ルールを有効にできません。

Store State Between Scheduled Runs

Standalone workflows don't have dedicated local storage. When a scheduled rule needs to remember a small amount of state between runs, you can store this data in a dedicated issue and use the search property to select this issue as the rule target. This dedicated issue is sometimes called an anchor issue

Use this approach only for small amounts of non-sensitive workflow state. For example, you can store the date of the last notification or a list of issue IDs that were already included in a report. If you package the workflow as an app or need structured app-owned data storage, use app global storage instead.

To store state in an anchor issue:

  1. Create a dedicated issue in the project where the workflow is attached.

  2. Make the issue visible only to the users who maintain the workflow.

  3. Use the issue description to store a small JSON object.

  4. Set the search property of the on-schedule rule so it only matches the anchor issue.

  5. In the rule action, read and update the JSON object stored in ctx.issue.description .

The following rule runs once a day and sends the project lead a list of issues that are pending review. The rule uses the anchor issue description to remember which issues have already been reported.

const entities = require('@jetbrains/youtrack-scripting-api/entities'); const search = require('@jetbrains/youtrack-scripting-api/search'); exports.rule = entities.Issue.onSchedule({ title: 'Notify project lead about pending reviews', search: 'issue id: DEMO-1', cron: '0 0 9 ? * MON-FRI', action: (ctx) => { const anchor = ctx.issue; const storedState = anchor.description ? JSON.parse(anchor.description) : {}; const reportedIssues = storedState.reportedIssues || {}; const issues = search.search( anchor.project, 'State: {Pending Review} #Unresolved', ctx.currentUser ); const issuesToReport = []; issues.forEach((issue) => { if (!reportedIssues[issue.id]) { issuesToReport.push(issue); reportedIssues[issue.id] = true; } }); if (issuesToReport.length) { const issueList = issuesToReport.map((issue) => issue.id + ' ' + issue.summary).join('\n'); anchor.project.leader.notify('Issues pending review', issueList); } anchor.description = JSON.stringify({ reportedIssues: reportedIssues, updated: Date.now() }, null, 2); } });
2026 年 5 月 12 日

関連ページ:

ローカライズされたワークフローメッセージ

YouTrack サーバーの言語設定はシステム全体で設定されます。通知とメッセージを含むワークフロールールを作成するときは、システムで使用されている言語でテキストを入力してください。YouTrack にバンドルされているデフォルトのワークフローは、サポートされているすべての言語にローカライズされています。これらのワークフローは、関数を使用して、ローカライズされたテキスト文字列を作成します。この関数はソース文字列を参照し、システムで使用されるデフォルト言語に基づいてローカライズされた文字列を返しま...

ステートマシンルール

state-machine ルールは、カスタムフィールドのある値から別の値への遷移を規制します。ステートマシンルールは、列挙された任意のカスタムフィールドに適用できます。ただし、ステートマシンルールの最も一般的な使用例は、状態フィールドまたはタイプを格納する別のカスタムフィールドの値間の遷移を調整することです。ステートマシンルールがプロジェクトに適用されると、フィールドのドロップダウンリストに表示されるオプションは、現在の状態のステートマシンルールで定義されている遷移に制限されます。ステートマシン...