Forums

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

How to clear custom fields when cloning an issue

Katie_R
Contributor
June 8, 2022

Our customer has asked if there is a way to clear two custom fields when an issue is cloned. We are using Jira Data Center 8.20.5 and have ScriptRunner. We did find a script in the community that works for this, but it uses a specific issue type so it won't work for us. This would be for cloning any issue type. The two fields are a radio button and a database picker that goes into a specific table and then allows you to select one or more sprints from the table. Here is the script we are starting with that we got from another community post but we can't seem to figure out how to correct it to what we want:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.user.ApplicationUser

Long ISSUE_LINK_TYPE_ID = xxxxx
Long TEXT_CUSTOM_FIELD_ID = yyyyy
String ISSUE_TYPE_ID = "zzzzz"

IssueLink issueLink = event.getIssueLink()
if (issueLink.getIssueLinkType().getId() != ISSUE_LINK_TYPE_ID) {
return
}
MutableIssue issue = issueLink.getSourceObject()
if (issue.getIssueType().getId() != ISSUE_TYPE_ID) {
return
}
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomField textCustomField = customFieldManager.getCustomFieldObject(TEXT_CUSTOM_FIELD_ID)
issue.setCustomFieldValue(textCustomField, null)
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Any assistance is appreciated. Thank you!

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events