How do I write a groovy expression for my workflow post-function

JIRA version: 6.4.11

(1)

Post function: Set Field Value to constant or Groovy expression

I want to set the fix version via  Set Field Value to constant or Groovy expression. I tried this script, but didn't work for me. 

if(issue.get("fixVersions").getName() == "5.0.6")
{
return "SasS 5.0.6";
}
else
{
return "";
}

 

(2)

Post function: Transition issue

I want to transition, when the fix version is not set to "SaaS 5.0.6". I tried this script, but didn't work. 

issue.get("fixVersions").getName() != "5.0.6")
return true;} else {
return false;
}

Please provide a solution for me to resolve these issues

Cheers.

Ganga

3 answers

0 votes
Steven Behnke Community Champion Jul 26, 2016

Do you get any errors on-screen or in your atlassian-jira.log file when these fail?

As documented here, issue.get("fixVersions") will return a collection of Version objects. Simply using getName() will not work - you need to iterate over the collection and check the name of each version object.

Thanks for the quick response. 

Do you have an example, so that I can try?

Thanks,

Ganga

 

 

could you please provide some example? thx

Hi Petar,

I was able to set fix version using with below code via "Set Field Value to constant or Groovy expression" post function.

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.project.version.VersionManager

import com.atlassian.jira.project.version.Version

 def vers = ComponentAccessor.getVersionManager().getVersion(20142)

def versionname = vers.getName()

if (versionname  != "SaaS 5.0.6")

{

    return versionname;

}

My next question, I would like to stop performing a transition, if a particular fix version is set. If there any post function or code that I can use to validation this request?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.jira.project.version.Version

def vers = ComponentAccessor.getVersionManager().getVersion(23240)
def versionname = vers.getName() 

def verdesc = vers.getDescription()

if (versionname  == "5.0.6")
{
    return "SaaS 5.0.6";
}
else
{
   return "";
}

I executed this script to update fix version via post function, but it didn't work and also I am not seeing any error on JIRA log. 

 

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,167 views 13 19
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot