Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,497
Community Members
 
Community Events
184
Community Groups

Groovy for boolean clone check

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!

2 answers

1 accepted

1 vote
Answer accepted
David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 29, 2023

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.

This did exactly what I need, thank you!

0 votes
Clark Everson
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 28, 2023 • edited

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)
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.22.6
TAGS
AUG Leaders

Atlassian Community Events