Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Using issuefactory cloneIssue copies "Time Logged" to new issue

Jon Sword
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 7, 2011

Hi,

I have written a groovyscript post process to clone issues. It works as expected except "Time Logged" for the parent issue appears to be copied to the clone. (NB: The worklog entries do not appear under the "Work Log" tab - but the "Logged" progress bar on the right side displays the time worked.)

The bare bones/stripped down code looks like this:

log = Category.getInstance("com.onresolve.jira.groovy.AutoClone")

issueMgr = componentManager.getIssueManager()
IssueLinkTypeManager issueLinkTypeManager = ComponentManager.getComponentInstanceOfType(IssueLinkTypeManager.class)
issueFactory = componentManager.getIssueFactory()
projectMgr = componentManager.getProjectManager()
VersionManager versionManager = componentManager.getVersionManager()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
User currentUserObj = UserUtils.getUser(currentUser);
JiraAuthenticationContext authenticationContext = componentManager.getJiraAuthenticationContext()
Issue issue  = issue
private final WorklogManager worklogManager = componentManager.getWorklogManager();

result = [[VersionName:"mas_16.0", VersionType:"Design", CloneTo:"Y", CloneFrom:"Y", Archived:""]]


// Start creating clones for applicable versions
def wasIndexing = ImportUtils.indexIssues
ImportUtils.indexIssues = true

int i = 0 ;
result.each {
     fixVersion = result.VersionName[i].toString()
     versionType = result.VersionType[i].toString()
     forecastLoad = result.Load[i].toString()
     i++

     newissue = issueFactory.cloneIssue(issue)
     if ( issue.summary =~ /CLONE - .*/ ) {
         newissue.setSummary("$issue.summary")
     } else {
         newissue.setSummary("CLONE - $issue.summary")
     }
     newissue.setProjectId(issue.projectId)
     newissue.setDescription(issue.description)
     newissue.setAssigneeId("Unassigned")

     for (CustomField cf : customFieldManager.getCustomFieldObjects(issue)) {
         if (issue.getCustomFieldValue(cf)) {
log.error "Custom field to copy: " + cf.name
             newissue.setCustomFieldValue(cf, issue.getCustomFieldValue(cf))
         }
     }

     OptionsManager optionsManager = ManagerFactory.getOptionsManager();

     //  Set the Fix Version for the new clone
     def cfFixVersion = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Fix Version'}
     newissue.setCustomFieldValue(cfFixVersion, versionManager.getVersion(issue.projectId, fixVersion))


     //  Create the issue!!
     issueMgr.createIssue(currentUserObj, newissue)

     //  Get the current list of outwards depends on links to get the sequence number
     linkMgr = ComponentManager.getInstance().getIssueLinkManager()
     def sequence = 0
     //for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
     //    if ("Depends" == link.issueLinkType.name) {
     //        sequence++;
     //    }
     //}

     Collection cloneIssueLinkTypes = issueLinkTypeManager.getIssueLinkTypesByName("Cloners")
     for (Iterator iterator = cloneIssueLinkTypes.iterator(); iterator.hasNext();) {
         IssueLinkType issueLinkType = (IssueLinkType) iterator.next();
         if (issueLinkType.getName() == "Cloners" ) {
             cloneIssueLinkType = issueLinkType.getId();
         }
     }
     linkMgr.createIssueLink (issue.id, newissue.id, cloneIssueLinkType, sequence, currentUserObj)
     log.error "Created CLONE "+newissue.id+" for "+fixVersion
}
ImportUtils.indexIssues = wasIndexing

Any thoughts on how I can prevent this information from being copied over by issueFactory.cloneIssue?

Thanks,

Jon

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Bob Swift (personal)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 7, 2011
Jon Sword
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 7, 2011

Great stuff Bob!

From your example I was able to do a quick Google to find the syntax I needed was "issue.setTimeSpent(null)". I did not expect it to be so simple :)

TAGS
AUG Leaders

Atlassian Community Events