Hello!
I'm trying to write a postfunction for my workflow that will clear fields from cloned issues when they're created. We have JMWE, JSU, and Scriptrunner to work with, but I am not very savvy with Groovy and am having trouble scripting a condition that will tell me if the created issue is linked to anything else as "clones". Our users change the summary, so checking the summary for "CLONE -" is not an option.
Thanks in advance!
Hi @Cailin Che
this is the code to use to run the JMWE post function (on the Create transition) only for cloned issues:
issue.key != null
However, you need to make sure the post function is placed before the "Creates the issue originally" post function.
The reason this works is that when cloning an existing issue, the issue.key variable is set to the issue key of the source issue, whereas it is empty (null) when creating a new issue from scratch.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Cailin Che
I am no expert but you can try this either but often times it's hard to get scripting help on here. You may have better luck reaching out to adaptivist directly. You would want to make a script runner listener and make sure to replace the custom field ids
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
// Add the field IDs you want to clear in the list below
def fieldsToClear = ["customfield_10000", "customfield_10001"]
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issue = event.issue
def sourceIssue = issueLinkManager.getOutwardLinks(issue.id)?.find {it.issueLinkType.name == "Cloners"}?.sourceObject
if (sourceIssue) {
fieldsToClear.each { fieldId ->
def customField = customFieldManager.getCustomFieldObject(fieldId)
if (customField) {
def changeHolder = new DefaultIssueChangeHolder()
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), null), changeHolder)
}
}
// Reindex the issue after clearing fields
issueManager.reindex(issue)
}
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.