How to find specific related issue using Groovy scripting in Post Function

Vivienne Barrett November 11, 2020

Hi there, 

I need to set a specific value on a custom field within some linked issues but not all of them. 

I'm using the 'Set field value of related issues (JMWE app)' Post Function and am using the 'Issues Returned by the following Groovy script' option to find the specific related issues that I require updated. 

From the research I've carried out to date the following syntax returns a list of all of the related issues 

issue.getLinkedIssues()

And these are the results:

Result type:
ArrayList
Result value:
[Test-250, Test-249]

So this gives me all the related links which is great but I need to break that down further and only have the 'Result Value = Test-249' and not just list all of the related issues. 

Is this doable? Does anyone have the correct syntax to use in this scenario? 

Any help appreciated... 

Thanks

 

2 answers

0 votes
David Maurel January 18, 2023

Hi,

That's an old subject but I have a very similar question to this, and cannot find the answer.

I would like to use the same post function, but to retrieve issues with a given set of link types. In the above answer, I tried to replace "issuetype" by variants of "issuelinktype", without success. Does anyone know how to do this ?

Thanks

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 18, 2023

@David Maurel 

why would you even need to use a Groovy script for that? You can simply use one Set field value of related issues (JMWE app) post-function per link type.

But if you really want to use a single post-function, and use the 'Issues Returned by the following Groovy script' option, the script could be:

issue.getLinkedIssues("link type direction name 1") + issue.getLinkedIssues("link type direction name 2") + issue.getLinkedIssues("link type direction name 3")

Note that you need to use link direction name (e.g. "blocks" or "is blocked by") and not the link type name ("Blocks")

David Maurel January 19, 2023

Thanks @David Fischer , I didn't think I could add the issues simply with the operator "+". As for the reason to do this, Here is a screenshot of the actual post-function implemented with another plug-in that you will surely recognize, and which I want to rewrite with JMWE. screenshot_20230119-01.jpg

Several link types (but not all), several fields updated, all in a single post-function. The JMWE "Set field value" allows to set value for only one field. If I had to rewrite this specifying only one link type, I would have to add (number of link types)x(number of fields to be updated) post-functions !

JMWE has multiple benefits compared to the other plug-in, but the ability to set value for multiple fields at once is clearly missing.

Regards,

David

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2023

Hi David,

Thanks for the clarification. 

You can use the + operator between lists and arrays, which is what getLinkedIssues returns. 

As for a Set Issue Fields post function, it already exists in JMWE for Jira Cloud and will be coming to Jira server soon. 

David Maurel January 19, 2023

Thanks. Actually we ARE migrating to Cloud, our Go Live is in 18 days. In our Server instance, we used JWT until now, but I wanted to change so we purchased a license for JMWE Cloud. Instead of rewriting all post-functions with JMWE after the migration, I reckoned that I could do the rewriting in our Server instance, before the migration (thus using a trial license of JMWE Server), and then use the JMWE migration path.

When the migration is complete, I will take the time to "factorize" my multiple set single field value post-functions into one.

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2023

Be careful though, because of major architecture differences between Jira Server and Jira Cloud, JMWE is also fairly different and, in particular, all scripts will need to be rewritten during the migration. Check https://appfire.atlassian.net/l/cp/zx4pjeCU for details.

David Maurel January 19, 2023

That is bad news indeed. I didn't clearly understand that Groovy was dismissed, and 80% at least of my post-functions have Groovy expressions... I guess it's better to have them migrated and having to change the expressions afterwards, than having to recreate all post-functions, since I only have a week-end to do that. Fortunately lots of them have simple expressions like constants or things like issue.get("assignee").

Do you know any converter from Groovy expressions to Nunjucks or Jira expressions ? Or tips to do it more easily than having to learn these languages from scratch ?

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2023

Unfortunately there is no converter, and the languages are very different. But Nunjucks is actually fairly simple, and JMWE does help you identify what needs to be updated once on Cloud

0 votes
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 11, 2020

What is your criteria for filtering the linked issues? How do you decide which linked issues should be updated?

Vivienne Barrett November 17, 2020

Hi David, 

The linked Issues are all using the same Link Type so I'm thinking that the best way of filtering the issues so that I just update the one I need to is via the 'Issue Type' name...

Is that feasible? 

 

Rgds,
Vivienne

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 17, 2020

Hi Vivienne,

sure, you could do something like:

issue.getLinkedIssues()?.findAll{it.get("issuetype")?.name in ["Bug","Task"]}

to return all linked issues of type Bug or Task.

Vivienne Barrett November 18, 2020

Hi David, 

That worked... 

Thank you so much for the help on this... appreciate it. 

Rgds,
Vivienne

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events