Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set Epic of task/story based on epic name

Philip Wroblewski
Contributor
September 13, 2018

Hi,

This question relates to Jira Misc Workflow Extension.

We have a Service Desk project, and a Jira project for every client. When a code issue is identified via a customer issue in the Service Desk project, we create a linked task in the right Jira project.

Each Jira project has a "Production Support" epic. 

What I would like to do, is to set the epic of the Task to this Epic using JMWE. However I would need to find the epic ID within the project (they will all be named the same). Is there a way to do this in the query?

 

Thanks,

Philip

2 answers

1 accepted

1 vote
Answer accepted
David Fischer
Community Champion
September 14, 2018

So this is the right approach, but if you use the "Test Nunjucks Expression" button, you'll notice it doesn't quite work, because there are a number of errors in your expression:

  1. you forgot to close the double quotes around the JQL string, as well as the parenthesis
  2. Once you close them, you'll get an error saying that the EpicName field doesn't exist. That because it's called "Epic Name".
  3. Once you fix that, assuming an Epic is found, the result of the filter is an array of Epics (Issues) so you need to get the first one, and then extract its issue key

So the correct expression is:

{{ ("project=" + issue.fields.project.key + " AND 'Epic Name' IN ('Production Support')") 
| searchIssues(maxResults = 1, fields='key')
| first
| field("key") }}
Philip Wroblewski
Contributor
September 14, 2018

Hi David,

 

That's excellent, and works well! I had noticed it wasn't working with testing, however was still trying to get my head around the syntax. Slowly getting there now, thanks!

 

Philip

Philip Wroblewski
Contributor
September 18, 2018

Hi @David Fischer -

 

I've realised I also need to add a condition to this item, so that the Epic is only set when the item is created from our Service Desk project (otherwise it is being set for every new item created). 

I've tried a couple of variations to the Nunjucks template in the condition, based on examples in the documentation. However, they both always return false, so there must be something wrong. Any idea on how to fix? Also, is there a good way to test these, e.g. by running specific components of the logic? 

 

Attempt 1:

{{ issue.fields["Linked Issues"]
| first
| field("project.key") == "HD"
}}

 

Attempt 2: 

{% set items = issue.fields["Linked Issues"] %}
{% set trigger = false %}
{% for item in items %}
{% if item.fields.project.key == "HD" %}
{% set trigger = true %}
{% endif %}
{% endfor %}
{{ trigger }}

David Fischer
Community Champion
September 19, 2018

Hi Philip,

how are you setting the Epic field? In a Set Field Value post-function put on the Create transition of the customer task workflow?

I assume that task is linked to the JSD issue through a specific link type, right? Let's say that link type (from task to JSD request) is "comes from". Then the conditional execution code would be something like:

{{ issue | linkedIssues("comes from") | first | field("fields.project.key") ==  "HD" }}
Philip Wroblewski
Contributor
September 19, 2018

That works, thanks David. I guess now that with my "issue.fields["Linked Issues"]" I was getting a list of IDs, rather than the objects themselves that your query is doing. 

David Fischer
Community Champion
September 19, 2018

Actually, issue.fields["Linked Issues"] returns an array of issue links - you can see the whole structure using the dump filter:

{{ issue.fields.issuelinks | dump(2)}}

As you'll see, the linked issues are present but with only a very limited list of fields, and the project field is not one of them. 

0 votes
Philip Wroblewski
Contributor
September 13, 2018

From my reading, it feels like something like the below would work for the Post-Function Set Field Value, EpicLink, but my syntax must be off as it isn't working. 

 

{{ ("project=" + issue.fields.project.key + " AND EpicName IN ('Production Support') | searchIssues(maxResults = 1, fields='key') }}

 

 

 

David Fischer
Community Champion
September 14, 2018

Hi Philip,

from this example, I assume you're on Jira Cloud, correct?

In which post-function are you trying to set the Epic Link field? Create Issue (while creating the linked task) or some other post-function?

Philip Wroblewski
Contributor
September 14, 2018

Hi David,

 

That's right, on Jira cloud. And it was in the Create Issue post function. 

 

Thanks,

Philip

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events