Transition Linked Issues Post-Function -- How to add a condition that checks the linked issue's project name

I am using this plugin to transition linked issues when the link type is fixed by, but I only want the post-function to execute when the linked issue is in a certain project. I want to add this in the condition section. How can I achieve this? 

3 answers

1 accepted

You can try the following (untest) Groovy condition script:

linkedIssue.get("project").getKey() == "<project key>"

Thank you! It works. 

David,

Can this be extended to be project or project category specific?

 

For example, something like this:

If project in A, or B, or C

Then
linkedIssue.get("project").getKey() == "<project key>"
Or maybe something like this:
project category = X
Then
linkedIssue.get("project").getKey() == "<project key>"

For multiple projects, you can do something like:

linkedIssue.get("project").getKey() == "A" || linkedIssue.get("project").getKey() == "B" || linkedIssue.get("project").getKey() == "C"

And for a project category:

linkedIssue.get("project").getProjectCategoryObject().getName() == "&lt;project category name&gt;"

David,

I modified the code a little.  I want to ensure the current issue is in project category "Learn" and the linked issue is in project CS.

I was able to get the first half of the conditional statement working, but have not been able to get the linked issue to transition.

 

I think I am looking for something like this

issue.get("project").getProjectCategoryObject().getName() == "Learn" &amp;&amp; linkedIssue.get("project").getKey() == "CS"

 

Each condition works on it's own, but when I try to concatenate the two statements, the linked issue does not transition

And yet the condition seems to be correct. Are you sure you can reach the two conditions at the same time? 

I modified the post function to test each part of the expression

 

When I set the expression to just this:

issue.get("project").getProjectCategoryObject().getName() == "Learn Tech"

the linked issue is not transitioning as expected.

 

When I set the expression to just this:

linkedIssue.get("project").getKey() == "CS"

The linked issue transitions as expected.

So there is something in the first expression that is not right. Please note that I have updated my examples to show that my project category has a space in the name.

Any error in the logs? (atlassian-jira.log)

Nope, nothing in the logs at all

I see this when configuring the post function:

"log: a Logger instance that writes into atlassian-jira.log (useful for debugging)"

How do I add log to the expression?

You can do something like:

log.error("project category: "+issue.get("project").getProjectCategoryObject().getName());
return issue.get("project").getProjectCategoryObject().getName() == "Learn Tech" &amp;&amp; linkedIssue.get("project").getKey() == "CS"

OK, I added the follow statements:

log.error("project category: "+issue.get("project").getProjectCategoryObject().getName());
log.error("linked project:"+linkedIssue.get("project").getKey());
return
issue.get("project").getProjectCategoryObject().getName() == "Learn" &amp;&amp; linkedIssue.get("project").getKey() == "CS"

 

 The values being returned to the log are correct:

project category: Learn Tech
linked project:CS

 

The linked issue is still not being transitioned sad Ugh

You left "Learn" instead of "Learn Tech" in your test

Sorry just a typo in the response above. The code in JIRA states Learn Tech

log.error("project category: "+issue.get("project").getProjectCategoryObject().getName());
log.error("linked project:"+linkedIssue.get("project").getKey());
return
issue.get("project").getProjectCategoryObject().getName() == "Learn Tech" &amp;&amp; linkedIssue.get("project").getKey() == "CS"

Holy Cr@p I found the issue.

My project category had a trailing space in the name!!

Once I edited the project category to remove the training space, the linked issue transitioned as expected.

 

Thank you so much for all your help and patience with this.

On the plus side, the post function did exactly what it was supposed to do. Since the project category did not match the groovy expression, the linked issue was not transitioned. smile

I'm glad you found your problem! I'm sorry, I should have thought to ask.

If you are satisfied with our product and our support, would you mind providing a quick review for us in the marketplace? [This link| https://marketplace.atlassian.com/plugins/com.innovalog.jmwe.jira-misc-workflow-extensions/cloud/reviews] will take you directly to the reviews page.

Much appreciated!
David

Are you running JMWE on JIRA Server or JIRA Coud?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

361 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you