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!
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.