Hi,
I would like to change the issue type from "Bug" to "support" with a groovyscript when a user clicks on a transition "Start Progress". How can I get "this Issue" in a Postfunction? and which objects do I need?
P.S.: both issue types use the same workflow.
Tanks for your help,
Raffy
Community moderators have prevented the ability to post new answers.
As stated in comments - you should be sure that issue types share field configuration and at the least workflow states. For details look at implementation of com.atlassian.jira.web.action.issue.MoveIssue* actions.
If you search for scriptrunner examples, you would find out that issue is accessible as 'issue', so
import com.atlassian.jira.component.ComponentAccessor def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="support"} if (newIssueType) issue.setIssueTypeObject(newIssueType)
UPDATE 2015-07-15: corrected code as suggested below by @Joe Smith
Thanks Jozef,
I am sure that the workflow and the field configuration scheme are the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jozef,
your solution is pretty much coller than my solution:
import org.apache.log4j.Category import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.issuetype.IssueType import com.atlassian.jira.issue.IssueImpl /* Define a Logger */ def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") log.setLevel(org.apache.log4j.Level.DEBUG) def constantsManager = ComponentAccessor.getConstantsManager() Issue issue = issue log.debug ("### Other method ###") def newIssueType = ComponentAccessor.issueTypeSchemeManager.getIssueTypesForProject(issue.projectObject).find{it.name=="Task"} log.debug newIssueType.name if (newIssueType) issue.setIssueTypeObject(newIssueType) log.debug issue.name log.debug("############################# IssueType changed from 'Bug' to 'Task' ########################################")
But Unfortunately it did not work and I get javax.script.ScriptException (s) in the log file:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here are the errors:
2013-02-05 11:21:58,859 http-bio-8080-exec-15 ERROR admin 681x857x1 1w8c413 10.255.255.6 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: name for class: com.atlassian.jira.issue.IssueImpl 2013-02-05 11:21:58,859 http-bio-8080-exec-15 ERROR admin 681x857x1 1w8c413 10.255.255.6 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: name for class: com.atlassian.jira.issue.IssueImpl at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:138)
nevertheless thank you very much for your Help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
your error is in line log.debug issue.name
should be log.debug issue.issueType.name
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now it works. Tanks a lot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
jozef kotlár thanks for your example, but there it is actually slightly wrong... if (newIssueType) issue.setIssueObject(newIssueType) should be if (newIssueType) issue.setIssue*Type*Object(newIssueType) as in @dy raffy's example. Got me on the right track though. Thanks both
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The solution I was locking for is:
import org.apache.log4j.Category import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.issuetype.IssueType /* Define a Logger */ def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") log.setLevel(org.apache.log4j.Level.DEBUG) def constantsManager = ComponentAccessor.getConstantsManager() Issue issue = issue // This what I was looking for :-). As simple as it is, but I didn't know that. IssueType targetIssueType = null log.debug "IssueType old = " + issue.issueType.name collection = constantsManager.getAllIssueTypeObjects() iterator = collection.iterator() while(iterator.hasNext()){ issueType = iterator.next() if(issueType.name == "Support"){ targetIssueType = issueType } } log.debug targetIssueType.name issue.setIssueTypeObject(targetIssueType) log.debug "IssueType new = " + issue.issueType.name
Why should this be dangerous? It's used deliberately.
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.
Yes, the Field Configuration Scheme is also the same for both issue types.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks a bit dangerous. Btw, it is not just workflow, it is also the Field Configuration Scheme that should be same for both issue types.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.