Forums

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

Copy value of custom field to another field when cloned

Hajar Rahimi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 28, 2020

Hi, I would like one custom field value copy to another field in different issue whenever the issue clone (it is cloning from project A issue type X to Project A issue type Y). when I input the key of an issue to run the Groovy script against it (test groovy script), it's run successfully. but when a new issue clone, it does not copy the field value. it's just work on special issue key in test and does not work on every current issue.
Thanks and appreciate your help.

package com.onresolve.jira.groovy.test.scriptfields.scripts

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

 

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def totalRemaining = 0
issueLinkManager.getOutwardLinks(issue.id).each {
issueLink ->
log.error (issueLink.issueLinkType.name)
log.error (issueLink.getId().toString())
def x=ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14862")
log.error(issueLink.getDestinationObject().getCustomFieldValue(x).toString())
issue.setFieldValue("company",issueLink.getDestinationObject().getCustomFieldValue(x).toString())
}

1 answer

0 votes
Hana Kučerová
Community Champion
December 1, 2020

Hi @Hajar Rahimi ,

welcome to the Atlassian Community!

Where exactly is your script inserted, when it doesn't work? Is it a post function in workflow?

How exactly do you do the clone operation? Do you use the ScriptRunner's "Clones an issue, and links" post function? Or is it the standard Jira clone functionality?

Thank you.

Suggest an answer

Log in or Sign up to answer