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?
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dona Dianisya,
First, you will need to configure it on the status itself, not the transition:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much for your guidance! Your answer helps me so much.
This suit on our Approval.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.