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?
Hi @Szymon F ,
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
cool (y)
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.