Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Clone fails if the user is invalid

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

 

1 answer

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

Aditya,

 

What plugin, version, and type of post function are you using?

Tim,

Below are the details

Plugin and version - Scriptrunner version 5.5.0

Postfunction - Custom script post-function

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.

Let me give it a try again and will update the results

Like Tim Perrault likes this

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you