Skip to main content

Jira example: Show who edited a work item

This fragment lists everyone who has changed the current work item. It reads the work item's change history and shows each person once. You can use it as a starting point for any panel that reads the change log.

Applies to: Script Master for Jira Β· Cloud. The editor's Display contributors template does the same job.

Set it up​

  1. Create a fragment with Location set to Work item panel.
  2. Paste the code below into Frontend HTML + JavaScript.
  3. In the preview, pick a work item that several people have edited, and check the list.
  4. Turn on Enable and select Save.

Result: On a work item, View app actions > Custom Panels shows the fragment, with the names of everyone who changed the work item.

The code​

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@atlaskit/css-reset@3.0.1/dist/bundle.css" />
<div>
Contributors: <div id="contributors">Loading...</div>
</div>

<script type="module">
// Follow the viewer's light or dark theme
document.querySelector(":root").setAttribute("data-color-mode", theme.colorMode);
document.querySelector(":root").setAttribute("data-theme", `${theme.colorMode}:${theme.colorMode}`);
document.querySelector(":root").insertAdjacentHTML("afterbegin", `<link rel="stylesheet" href="https://forge.cdn.prod.atlassian-dev.net/atlaskit-tokens_${theme.colorMode}.css" />`);

const context = await view.getContext();
const issueKey = context.extension.issue.key;
const response = await requestJira(`/rest/api/3/issue/${issueKey}/changelog`, {
headers: { 'Accept': 'application/json' }
});
const responseData = await response.json();
const allContributors = responseData.values.map(entry => entry.author.displayName);
const uniqueContributors = Array.from(new Set(allContributors)).join(', ');

document.getElementById('contributors').textContent = uniqueContributors;
</script>

The change log endpoint returns one page of entries, up to 100. On a work item with a longer history, the list covers the first page only.