Customize Jira Update Issue steps to add labels

Flow Designer comes with built-in steps for Jira Cloud and Jira Server. These steps let you create, update, and add comments to issues at any point in your flow.

The built-in steps are convenient, but they might not always do exactly what you want. For example, what if you want to add a label to the existing ones, but when you set the Label input in the Update Issue step, the labels on the issue are replaced? Well, you can do that too, and we'll walk you through how to copy the step as a custom step and tweak its settings to make it happen.

Create a copy of the step

  1. Open a flow in Flow Designer. Any old flow will do, but let's open the one where you want to use the step so you have one less step later.
  2. Click on the Apps tab in the palette, and find the step you need to copy: the Update Issue step in either the Jira Cloud section or the Jira Server section, depending on which tool you're using.
  3. Click the gear icon beside the step and select Copy as Custom. This opens up the New Custom Step dialog box.
  4. Give the new step a name, let's say Jira Cloud - Update Issue (labels). This lets you find it in the Custom tab of the palette.
    • You can also update the description to let your teammates know this version of the step adds to the list of labels rather than replacing them.

Update the script

  1. Click on the Script tab.
  2. Find and replace the lines of code outlined in the sections below for Jira Cloud and Jira Server.
  3. Click Save.

Your custom step is now ready to use — you can find it on the Custom tab in the palette. Add it to a flow and check to see that it's adding labels to any existing ones.

Updates to the Jira Cloud step script

Replace lines 11-28 — starting at var payload = { — with:

var payload = {
fields: {
description: withContext(description),
environment: withContext(environment),
summary: input['Summary']
},
update: {
labels: labelsArray
}
};

var payload = {
fields: {
description: withContext(description),
environment: withContext(environment),
summary: input['Summary']
},
update: {
labels: labelsArray
}
};

Here's the existing code for reference:
JiraCloud11-28.png

Updates to the Jira Server step script

Replace lines 11 to 32 — starting at var payload = { — with:

var labels = input['Labels'];
var labelsArray;
if (labels) {
labelsArray = labels.split(',').map(function(element) {
return { add: element.trim() };
});
}

var assignee = input['Assignee Key'];
var priority = input['Priority'];
var reporter = input['Reporter Key'];
var payload = {
fields: {
assignee: assignee ? { name: assignee } : undefined,
description: input['Description'],
environment: input['Environment'],
priority: priority ? { name: priority } : undefined,
reporter: reporter ? { name: reporter } : undefined,
summary: input['Summary']
},
update: {
labels: labelsArray
}
};

 Here's the existing code for reference:
JiraServer11-32.png

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.