How can reset a custom field after clone a issue?

Ana Parra Saura April 30, 2019

I want to reset a field when clone a issue. I had a Script listener in groovy, but didnt work.

 

 

import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.security.JiraAuthenticationContext
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor


Issue issue = event.issue;
IssueManager issueManager = ComponentAccessor.getIssueManager()
MutableIssue mIssue = issueManager.getIssueObject(issue.getKey())
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def fieldManager = ComponentAccessor.getFieldManager()

def VALID_ISSUETYPES = ["Incident","Query","Task"]
String proyecto = issue.getProjectObject().getKey()

try{

if(proyecto.equals("AAA")){
if(VALID_ISSUETYPES.contains(issue.issueTypeObject.name)){
log.warn("Project --> ${proyecto}")
log.warn("Issue --> ${issue}")
log.warn("IssueKey --> ${issue.key}")
log.warn("event --> ${event.issue}")
log.warn("event --> " + event.issue)
log.warn("issue.getId --> " + issue.getId())
log.warn("---issue --> " + issue.getProperties())
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
log.warn("allOutIssueLink --> " + allOutIssueLink)
log.warn("allInIssueLink --> " + allInIssueLink)

log.warn("allOutIssueLink size --> " + allOutIssueLink.size())
log.warn("allInIssueLink size --> " + allInIssueLink.size())

for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
log.warn("issueLink --> " + issueLink)
MutableIssue linkedIssue = (MutableIssue) issueLink.getDestinationObject()
log.warn("linkedIssue --> " + linkedIssue)
}
//def linksSystemField = fieldManager.getField("issuelinks")

//search  Issue Links : clones.

//set customfield
}
}
}catch (Exception e){
log.warn(e.getMessage()+"\n")
}

Thanks.

1 answer

1 vote
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 30, 2019

Hello @Ana Parra Saura 

Are you cloning a issue using the script runner post-function? Because if you are triggering the listener on the workflow transition then you can also use the Script runner built-in post-function for clone an issue and then just choose the fields which you want to copy and thus will not be required to write a listener.

Ana Parra Saura April 30, 2019

No, im cloning de issue manually.

Suggest an answer

Log in or Sign up to answer