I'm trying to add a post-function on create issue (which will assign the issue to a role), but only if a condition is true.
The custom field type is 'select list, single choice', so I assume the value is a string.
I added the code below for the condition, but when I click on the 'Test Groovy script' I get an error.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.opensymphony.workflow.InvalidInputException
def issue = issue as MutableIssue
final myField = "Product Name"
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName(myField)
def cfValue = issue.getCustomFieldValue(cf)
return (cfValue.startsWith("AA"))
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.customfields.option.LazyLoadedOption.startsWith() is applicable for argument types: (java.lang.String) values: [AA]
I tried to replace the literal "AA" with a variable (final foo = "AA") and use it instead, but I get the same error.
Thanks
Hi Amir,
are you sure you are using a Script Runner post-function? It looks like you might be using an Assign to Role Member post-function from JMWE instead.
Thanks, David, you are correct, it's indeed a JMWE post-function.
But, my understanding is that the condition is a pure groovy code. The UI says, "Only execute this post-function if the following Groovy expression returns true".
Just as a side note, unrelated to the problem, we also have the JEP plugin which offers this post-function: "JEP - Assign issue to a role, according to a field of issue".
I will try it and report back here, but I'm still curious why my groovy code fails.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The Condition is indeed a Groovy script, but you are also using an API. You can, as in your case, use the standard Jira API (as you would in ScriptRunner), but then the mistake in your script is that the getCustomFieldValue method returns an Option object, which in turn has a getValue() method that returns the String representation of that option.
Or you can use JMWE's simplified API:
issue.get("Product Name")?.startsWith("AA")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey David, thanks! I added the getValue() and it works:
def cfValue = issue.getCustomFieldValue(cf).getValue()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.