Hi ,
I am using the below code to clone issues which works fine until there is an user (in assignee field) who is invalid(no longer with company or without license) and haven't been removed from the user field. I am not sure if there is an option to bypass this field.
Any suggestions would be appreciated?
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
import org.apache.log4j.Logger
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import org.slf4j.LoggerFactory;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def changeHolder = new DefaultIssueChangeHolder()
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
//def log =LoggerFactory.getLogger("com.onresolve.jira.groovy")
def issueManager = ComponentAccessor.getIssueManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issue = issue
// **** start of cloning release logic ****
def toclone = issueFactory.cloneIssueWithAllFields(issue)
def cloned = issueManager.createIssueObject(loggedInUser,toclone)
log.info("CLONED ISSUE KEY: ${cloned.getKey()}")
// **** end of cloning release logic ****
You could add logic to see if the assignee is active and if not set to the current logged in user as assignee. I haven't tried it, but I think it should work.
if ( issue.assignee == null) {
issue.setAssignee(loggedInUser)
}
Hi Tim,
Thanks for the suggestion but I have tried it and it didn't work. this script copies the data as is and creates a new issue and since the user is invalid, it fails. The only option as of now is to replace the user or make the assignee field to blank before trying the clone.
However I want to somehow skip the assignee field if the user is invalid. Unfortunately this doesn't work at this moment.
Thanks
Aditya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Aditya,
What plugin, version, and type of post function are you using?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tim,
Below are the details
Plugin and version - Scriptrunner version 5.5.0
Postfunction - Custom script post-function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am running Version 6.41.0 and I am able to get it to work. It copies everything over, even an inactive user. To test I created a ticket and then after creation I deactivated and removed all groups from the user in the assignee. I was still able to clone and it just moved the inactive user to the new ticket as the assignee, which may not be the final result you want, but it didn't block the postfunction. Not sure if the version in plugin makes a difference. Code below. Removed like two lines and then just added a message at the end:
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
import org.apache.log4j.Logger
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import org.slf4j.LoggerFactory;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
def changeHolder = new DefaultIssueChangeHolder()
import org.apache.log4j.Category
log.setLevel(org.apache.log4j.Level.DEBUG)
def issueManager = ComponentAccessor.getIssueManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// **** start of cloning release logic ****
def toclone = issueFactory.cloneIssueWithAllFields(issue)
def cloned = issueManager.createIssueObject(loggedInUser,toclone)
log.info("CLONED ISSUE KEY: ${cloned.getKey()}")
// **** end of cloning release logic ****
UserMessageUtil.success("CLONED ISSUE KEY: ${cloned.getKey()}")
Are you getting any errors?
The other thought I had was instead of using the custom script postfunction you could try the Clones an issue, and links [ScriptRunner] postfunction if it is available in version 5.5.0. This would be the easiest way to do it, otherwise I think you will need to rework the script to pull all the fields and then set from that list you retrieved.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Let me give it a try again and will update the results
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.