Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner Listner cloning issue when custom field has value and avoid duplicates Edited

Hi Folks,

I am working on some simple script but it crashed some day ago and does not work anymore. 

This one should create a clone when a custom field is YES:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.link.IssueLink;


def customFieldManager = ComponentAccessor.getCustomFieldManager()
String customFieldValue = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject((13207 as long)))


if (customFieldValue == "Yes")
{
return true
}

 

also I wanted to add if condition to avoid duplicates:

if (customFieldValue == "Yes"
&& !issueLinkManager.getOutwardLinks(issue.getId())*.destinationObject.projectObject.name.contains('Known Issues'))

{
return true
}

 

For now, the first part is working. Can you give me a hand how to add the second part?

1 answer

1 accepted

0 votes
Answer accepted
Leo Community Leader Nov 05, 2019

Hi @Szymon Fijalkowski ,

You can try out below snippet, I just included my logic in your code

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.link.IssueLink;

def customFieldManager = ComponentAccessor.getCustomFieldManager()
String customFieldValue = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject((13207 as long)))

if (customFieldValue == "Yes" && !issueLinkManager.getInwardLinks(issue.getId())*.issueLinkType.name.contains('Cloners'))

{
return true
}

 

Note: I'm validating Inward link of event occurred ticket and passing Issue Link name which I used "Cloners" it has cloned by and clones link names as inward and outward 

Hope it gives you  some idea

 

BR,

Leo

I thought about something similar unfortunately the name can not be changed, even with some suffix or any tag.

Instead of name of issue/project may I use i.e. issue type? I have name = KI and id= 10902?

Leo Community Leader Nov 05, 2019

Then you may need to go with some huge script to iterate over linked issue and find their project name or issue type. I just written a script didn't validate it may need some minor changes. here I used both inward and outward functions. you can removed unwanted one based on your clone configuration but I would suggest you to keep both

import com.atlassian.jira.ComponentManager
import groovy.xml.MarkupBuilder
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;

import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.ListLinks")


def valid = true;
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
;
def linkedIssue = issueLink.getDestinationObject()
String type = linkedIssue.getIssueType().getName();
String project = linkedIssue.getProject().name
if(project == "Target Project name"){
valid = false
}
}
List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allInIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
;
def linkedIssue = issueLink.getSourceObject()
String type = linkedIssue.getIssueType().getName();
String project = linkedIssue.getProject().name
if(project == "Target Project name"){
valid = false
}
}
if(valid){
return true
}

 

BR,

Leo

Dear @Leo ,

thank you so much! it looks impressive for me. As far as I have tried it works. Now I need to add condition for the custom field.

 

Thank you!

 

----------------Added----------------

import com.atlassian.jira.ComponentManager
import groovy.xml.MarkupBuilder
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;

import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.ListLinks")

def customFieldManager = ComponentAccessor.getCustomFieldManager()
String cf = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject((13207 as long)))

if (
cf == "Yes")
{


def valid = true;
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
;
def linkedIssue = issueLink.getDestinationObject()
String type = linkedIssue.getIssueType().getName();
String project = linkedIssue.getProjectObject().name
if(project == "Known Issues"){
valid = false
}
}
List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allInIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
;
def linkedIssue = issueLink.getSourceObject()
String type = linkedIssue.getIssueType().getName();
String project = linkedIssue.getProjectObject().name
if(project == "Known Issues"){
valid = false
}
}
if(valid){
return true
}
}
else false

 

Leo Community Leader Nov 05, 2019

cool (y) 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

77 views 0 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you