JIRA Misc Workflows - Any examples for Field->Groovy expression?

Hey, so let's assume I don't really know how to write Groovy. But I looked at some sample scripts, and in trying to set a couple of User Picker fields (multiple users) based on what is in a Select field (Major or Minor), I naively tried this:

def severity = issue.get("customfield_10551").getValue() 

if (severity == "Major") {
   return 'dlprodalert' 
} else {
   return 'prodalertminor'
}

And I got slapped with this error:

2014-05-23 16:47:15,054 http-bio-8080-exec-193 WARN darryll 1007x6062x1 fk8wyq 69.53.237.72,10.200.150.205 /secure/QuickCreateIssue.jspa [jmwe.plugins.functions.SetFieldValueFunction] Error while executing SetFieldValueFunction: groovy.lang.MissingMethodException: No signature of method: java.lang.String.getValue() is applicable for argument types: () values: []
Possible solutions: getClass(), getAt(groovy.lang.IntRange), getAt(java.util.Collection), getAt(java.util.Collection), getAt(groovy.lang.Range), getAt(groovy.lang.Range)
groovy.lang.MissingMethodException: No signature of method: java.lang.String.getValue() is applicable for argument types: () values: []
Possible solutions: getClass(), getAt(groovy.lang.IntRange), getAt(java.util.Collection), getAt(java.util.Collection), getAt(groovy.lang.Range), getAt(groovy.lang.Range)

This (and the many other questions in this forum) could probably be avoided if the documentation offered a few examples of writing Groovy expressions.

Thanks!

1 answer

Hey Derryl,

try to use the following code :

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField severityCF = customFieldManager.getCustomFieldObjectByName("YOUR_CF_NAME_SEVERITY");
String severity = issue.getCustomFieldValue(severityCF)!=null?issue.getCustomFieldValue(severityCF).toString():"";
if("Major".equalsIgnoreCase(severity)){
	return "dlprodalert";
}
return "prodalertminor";

Please, change YOUR_CF_NAME_SEVERITY with your custom field name.

Hope this helps,

Fabio

Hey Fabio -- thank you for the example. Unfortunately I'm still getting an error:

/secure/QuickCreateIssue.jspa [jmwe.plugins.functions.SetFieldValueFunction] Error while executing SetFieldValueFunction: groovy.lang.MissingMethodException: No signature of method: com.innovalog.jmwe.IssueProxy.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [Severity]

I tested the script using Script Runner's console, and it worked like a charm:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;

// Added for testing in Script Runner Console
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.IssueManager;
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
Issue issue = issueManager.getIssueObject( "INC-996" );

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

CustomField severityCF = customFieldManager.getCustomFieldObjectByName( "Severity" );
String severity = issue.getCustomFieldValue(severityCF)!=null?issue.getCustomFieldValue(severityCF).toString():"";

if("Major".equalsIgnoreCase(severity)){
    return "dlprodalert";
}
return "prodalertminor";

I've tried various tweaks, but I just can't make any progress. Thanks again.

Hey Fabio -- thank you for the example. Unfortunately I'm still getting an error:

/secure/QuickCreateIssue.jspa [jmwe.plugins.functions.SetFieldValueFunction] Error while executing SetFieldValueFunction: groovy.lang.MissingMethodException: No signature of method: com.innovalog.jmwe.IssueProxy.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [Severity]

I tested the script using Script Runner's console, and it worked like a charm:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;

// Added for testing in Script Runner Console
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.IssueManager;
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
Issue issue = issueManager.getIssueObject( "INC-996" );

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

CustomField severityCF = customFieldManager.getCustomFieldObjectByName( "Severity" );
String severity = issue.getCustomFieldValue(severityCF)!=null?issue.getCustomFieldValue(severityCF).toString():"";

if("Major".equalsIgnoreCase(severity)){
    return "dlprodalert";
}
return "prodalertminor";

Thanks again!

I was thinking maybe the script doesn't think Severity is set yet. Is this because I'm trying to do this as a Post Function on Create? I've set these Post Functions to run last, well after "Creates the issue originally." and "Fire a ProdAlert Created event that can be processed by the listeners."

Is the problem that this Post Function can't figure out the severity of the current issue after Create?

"The value of field ProdAlert Notification List of the current issue will be set to the result of a Groovy expression (replacing existing values)"

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 ...

2,801 views 11 18
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