Forums

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

ScriptRunner CloneIssue not calling ADDITIONAL_SCRIPT

Damon Osgood
July 11, 2018

Hello!

I am trying to write a ScriptRunner groovy script that clones an issue. Eventually this will be a post-function that clones to multiple projects, but baby steps. 

As a test, here's my script that clones a hard-coded issue to another project.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
import org.apache.log4j.Logger
import com.atlassian.jira.issue.MutableIssue

def issue = ComponentAccessor.getComponent(IssueManager).getIssueByKeyIgnoreCase("SRC-1")
def clonesId = ComponentAccessor.getComponent(IssueLinkTypeManager).getIssueLinkTypes().findByName("Cloners")?.id

def cloneIssue = new CloneIssue()

def inputs = [
issue : issue,
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): """
issue.setSummary("CLONED: " + issue.getSummary())
checkLink = {link -> link.issueLinkType.name != "Cloners"}
""",

(CloneIssue.FIELD_COPY_COMMENTS) : true,
(CloneIssue.FIELD_TARGET_PROJECT) : "DEST",
(CloneIssue.FIELD_LINK_TYPE) : clonesId + " inward",
(CloneIssue.FIELD_SELECTED_FIELDS) : null, //clone all the fields
]

def errorCollection = cloneIssue.doValidate(inputs, false)
if (errorCollection.hasAnyErrors()) {
log.warn("Couldn't clone issue: ${errorCollection}")
}
else {
cloneIssue.doScript(inputs)
}

The issue does get cloned, but the ADDITIONAL_SCRIPT does not seem to get called. That is, the summary of the clone remains identical to the original, and all links are cloned.

Is there any trick to getting the ADDITIONAL_SCRIPT code to run?

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Jimmy Seddon
Community Champion
September 3, 2021

Hi @Dona Dianisya,

My best suggestion for accomplishing this would be to have multiple state transitions that act as those approval points (this is what I have setup in the past).

For example:

- The User creates an issue which goes to "Open".
- It gets moved (or you use automation rules) to move it to the "Waiting for Dept. Approval" and assign the department head as the approver.
-Once Approved by the Dept. Head, it moved to the Next State to be approved by IT... etc.

Additionally, when you configure the approval part of a state transition you can use a different User field, which is how I accomplished this.  So the Dept. Head became the "Approval" Field for the first start transition, and then I used different fields for the others.

I hope that helps you get to where you are looking to go.

-Jimmy

Dona Dianisya
Contributor
September 5, 2021

Hi @Jimmy Seddon 

Thanks for your best suggestion.

If you don't mind. Could you tell me how to set the multiple state transitions? Do I have to customize the workflow for it?

 

Thanks

-Dona

Dona Dianisya
Contributor
September 5, 2021

Hi @Jimmy Seddon 

I already added a new transition "Waiting for IT Approval" between "Waiting for Dept. Head Approval and "Waiting for Support" state.

So, how can I set that transition to be another approval statement?

If you don't mind, could you please guide me, please?

Thank you

approval workflow transition.png

Jimmy Seddon
Community Champion
September 6, 2021

Hi @Dona Dianisya,

First, you will need to configure it on the status itself, not the transition:

AddApproval.JPG

Second, in order to be able to see and configure the approvals, you need to make sure the workflow is active on a Jira Service Management project.

I hope that helps answer your questions.

-Jimmy

Like Dona Dianisya likes this
Dona Dianisya
Contributor
September 8, 2021

Hi @Jimmy Seddon 

Thank you so much for your guidance! Your answer helps me so much.

This suit on our Approval.

Like Jimmy Seddon likes this
Jimmy Seddon
Community Champion
September 8, 2021

I'm glad that will work for you!

Like Dona Dianisya likes this
TAGS
AUG Leaders

Atlassian Community Events