You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在YouTrack工作流脚本中创建新问题并跳转至编辑页面?

YouTrack脚本创建子任务后跳转至编辑页解决方案

你可以通过YouTrack工作流API内置的ctx.ui.openEditor()方法,直接在创建新子任务后打开其编辑页面,无需手动拼接URL或调用外部方法。

修改后的完整脚本

/**
 * 创建子任务并跳转至编辑页的工作流规则
 */

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

exports.rule = entities.Issue.action({
  title: '创建子任务',
  command: 'create_sub_task',
  guard: (ctx) => {
    // 可根据需求添加启用命令的条件,比如限制当前用户权限
    return true;
  },
  action: (ctx) => {
    const issue = ctx.issue;
    
    const createIssue = function(name) {
      const newIssue = new entities.Issue(ctx.currentUser, issue.project,
        `${name} for ${issue.summary}`);
      newIssue.fields.Type = "Detail";
      newIssue.links['subtask of'].add(issue);
      issue.links['parent for'].add(newIssue);
      newIssue.fields.Author = entities.User.current;
      
      return newIssue;
    };
    
    const newSubTask = createIssue('NewTask');
    // 核心逻辑:打开新子任务的编辑页面
    ctx.ui.openEditor(newSubTask);
  },
  requirements: {
    // 可添加依赖校验,比如确保项目中存在"Detail"类型的Issue
  }
});

关键说明

  • ctx.ui.openEditor(newSubTask)是YouTrack工作流提供的原生UI交互方法,会自动在当前浏览器窗口打开新创建问题的编辑界面
  • 无需手动拼接实例URL,方法会根据当前YouTrack环境自动生成正确的编辑页路径
  • 需确保执行脚本的用户拥有该新问题的编辑权限,否则无法正常打开编辑页

内容的提问来源于stack exchange,提问作者Igor Mazepa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 12:30:47