Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to copy issues after due date is passed to another project with groovy

Suketa October 30, 2023

Hey i need you help please.

I would like to copy issues from a project to another after due date is passed. 

I will put in place a job every 24 hours.

I work on jira 9.4.1 and scriptrunner 8.3.0.

I found other topics, i tried to build something but it's failed.

Anyone can help me please? 

3 answers

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
October 31, 2023

Hi @Suketa

From what you have described in your description, you are trying to copy over an issue from one project to another project after a certain time period.

There is already an example of how to copy the issue from one project to another project available in the Adaptavist Library.

Regarding the date when you want the script to execute, you could set something like an Escalation Service or a Custom Job to trigger the copying process.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

0 votes
Suketa October 30, 2023

It's ok for me.

I had to change def issueToCopy = issueManager.getIssueObject(issueKey)

by def issueToCopy = issueManager.getIssueObject(issueKey.getKey())

Thank you 

0 votes
Suketa October 30, 2023

I have tried something like this but an error occured. "IssueKey" can not be apply like this in method...

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils

import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue

import com.atlassian.jira.component.ComponentAccessor

 

def projectkey = "AAAA"

 

Issues.search('project = BBBBB AND duedate > startOfDay()').each {issueKey ->

 

    // do something

   

def projectManager = ComponentAccessor.projectManager

def issueManager = ComponentAccessor.issueManager

 

def projectToCopy = projectManager.getProjectByCurrentKey(projectkey)

def issueToCopy = issueManager.getIssueObject(issueKey)

 

def blockIntraprojectLinks = '{l -> l.sourceObject.projectObject != l.destinationObject.projectObject}'

 

//Set the creation parameters/inputs (use clone issue but with no link type)

def inputs = [

    (CloneIssue.FIELD_TARGET_PROJECT)       : projectToCopy.key,

    (CloneIssue.FIELD_LINK_TYPE)            : null,

    (ConditionUtils.FIELD_ADDITIONAL_SCRIPT): [

        "checkLink = $blockIntraprojectLinks;",

        ""

    ],

    (CloneIssue.FIELD_SELECTED_FIELDS)      : null, //clone all the fields

    (CloneIssue.SKIP_EPIC_LINKS)            : "true",

] as Map<String, Object>

def executionContext = [issue: issueToCopy] as Map<String, Object>

 

def newClonedIssue = ScriptRunnerImpl.scriptRunner.createBean(CloneIssue)

// Execute the clone action with the specified inputs

def updatedExecutionContext = newClonedIssue.execute(inputs, executionContext)

//The issue has been successfully cloned

assert updatedExecutionContext.newIssue

 

}

 

Suggest an answer

Log in or Sign up to answer