Open Workflow for current Issue

Looks up the workflow for the currently opened Issue and opens it in a new tab

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Open Workflow for current Issue
// @namespace    http://schuppentier.org/
// @version      0.2
// @description  Looks up the workflow for the currently opened Issue and opens it in a new tab
// @author       Dennis Stengele
// @match        https://*.atlassian.net/browse/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=atlassian.net
// @grant        none
// @run-at       context-menu
// @license      MIT
// ==/UserScript==

/* jshint esversion: 11 */

(async function() {
    'use strict';

    let issuekey = location.pathname.split("/").pop(); // This SHOULD be done with JIRA.Issue.getIssueKey(), but this seems to always return null in Cloud.
    let projectKey = issuekey.split("-")[0];
    let baseUrl = location.origin;

    let issueTypeId = await fetch(`${baseUrl}/rest/api/3/issue/${issuekey}`).then(
        response => { return response.json(); }
    ).then(
        json => { return json.fields.issuetype.id; }
    );

    let projectId = await fetch(`${baseUrl}/rest/api/3/project/${projectKey}`).then(
        response => { return response.json(); }
    ).then(
        json => { return json.id; }
    );

    let workflowName = await fetch(`${baseUrl}/rest/api/3/workflowscheme/project?${new URLSearchParams({ projectId: projectId })}`).then(
        response => { return response.json(); }
    ).then(
        json => { return json.values[0].workflowScheme.issueTypeMappings[issueTypeId] ?? json.values[0].workflowScheme.defaultWorkflow; }
    );

    let encodedWorkflowName = encodeURIComponent(workflowName);

    window.open(`${baseUrl}/secure/admin/workflows/ViewWorkflowSteps.jspa?workflowMode=live&workflowName=${encodedWorkflowName}`, "_blank");
})();