JIRA JMWE - Set field value (JMWE app) based on summary value

Josh Pulda May 18, 2021

I am working with JMWE and trying to write a groovy script where I want to check whether the summary of a ticket contains a specific string and then assign a ticket to a specified user if it does.

For example:

if (issue.get("summary").toLowerCase().contains("Check Refund")) { 'user1'}
if (issue.get("summary").toLowerCase().contains("Vendor Credit Memo")) { 'user1'}
if (issue.get("summary").toLowerCase().contains("Credit and Rebill")) { 'user1'}
else { 'user2'}

Is there a way to make this work? I am putting this post function on the 'create' workflow transition. I am also wondering if there is a functional wildcard to place within the quotes to parse any instance of the string, such as ("*Check Refund*").

1 answer

1 accepted

3 votes
Answer accepted
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.
May 18, 2021

Hi Josh,

yes, this can work. However, there are two problems with your code:

  1. you are comparing a lowercase version of the summary with a constant string that contains uppercase characters (e.g. "Check Refund"). That will never match
  2. You must return the value, to stop further execution of the script

A fixed version of the script would be:

if (issue.get("summary").toLowerCase().contains("check refund")) {return 'user1'}
if (issue.get("summary").toLowerCase().contains("vendor credit memo")) {return 'user1'}
if (issue.get("summary").toLowerCase().contains("credit and rebill")) {return 'user1'}
return 'user2'
Josh Pulda May 18, 2021

Thanks, David!

This checks out when I test the groovy script to an existing ticket.

 

What I should have mentioned in the original post is that my goal for this post function was to take a ticket that is created by an email handler and assign it based on what the summary contains. Do you know if this is possible?

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.
May 18, 2021

Hi Josh,

it is very unlikely that the email handler can skip the Create transition. That's the only way to create issues in Jira. Can you double-check?

Josh Pulda May 18, 2021

Hi David,

Brilliant! Upon further testing, I was still having issues - this was due to another post function counteracting the revised logic that we just discussed up above. Once that was removed, everything appears to be working just great!

Thank you for your help!

Suggest an answer

Log in or Sign up to answer