Hi Team,
On current issue.
I have a field called 'Liked Issue Keys' and it should display only linked issue keys with comma separated values based on linked issues custom fieldvalue(check box-A)= Yes.
Where were linked issues (custom field )checkbox = Yes, then the 'Linked Issue Keys' should only show those issuekeys.
Another custom field(check box-B) on current issue, should be checked automatically if 'Linked Issue Keys' !=null and if it is null and automatically unselect the checkbox-B.
Regards,
Suresh
Hey Suresh,
It looks like you're pretty close! You just may be overcomplicating it a bit. :D
I tried this out myself and came up with this:
import com.atlassian.jira.component.ComponentAccessor
//Get necessary managers
def cfm = ComponentAccessor.customFieldManager
def linkManager = ComponentAccessor.issueLinkManager
//Get check box field
def checkBoxA = cfm.getCustomFieldObjectByName("Check-Box-A") //Name of CF
def issueKeys = []
//Go through all linked issues and collect their keys if CheckBoxA is valued "Yes"
linkManager.getOutwardLinks(issue.id).each{
def linkedIssue = it.destinationObject
def checkBoxAValue = linkedIssue.getCustomFieldValue(checkBoxA)
//Checks that "Yes" is a selected value for check box A
if("Yes" in checkBoxAValue.collect{it.toString()})
{
issueKeys.add("${linkedIssue.key}")
}
}
if(issueKeys.size() > 0)
{
return issueKeys.join(',')
}
else
{
return null
}
I haven't completely tested this yet, but that should theoretically get you all of the keys from linked issues that have the value "Yes" for check box A.
Best,
Aidan
Thank you Aidan,
May I know the method to get In &Out wards linked issues.The Outwards method is getting linked issues list from current issue.Can any method will help us to get the issue linked in somewhere where Checkbox=yes
I am trying to get all linked issues.
linkManager.getInAndOutwardLinks(issue.id).each{
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you praveen, We have already tried this method, it is returning null. We may need to pass issuelinktype.id args to this method.looking on how to retrieve linktypeid, from that issue.id and return keys
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One more thing I would like to mention here,
On edit action the script custom field not updating, is this limitation/something can be doable.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Aidan Derossett [Adaptavist] Can you help me to retrieve all linked issue where linkedissue linktype ="Related to RoadMap" and check-Box-A =Yes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey again Suresh!
To get the inward links, you can use the same form as for getting outward links. So instead of "getOutwardLinks," you would use "getInwardLinks." And for inward links, you'd want the "linkedIssue" variable to be the sourceObject, not the destinationObject. Finally, to check for the link type, you simply need to do a comparison with the link type object's name:
//For example
if(it.issueLinkType == "Related to RoadMap")
{
//Do things
}
So all-in-all you'll need to change/add the following in your code:
linkManager.getOutwardLinks(issue.id).each{
def linkedIssue = it.destinationObject
def checkBoxAValue = linkedIssue.getCustomFieldValue(checkBoxA)
if(it.issueLinkType.name == "Related to RoadMap")
{
//Checks that "Yes" is a selected value for check box A
if("Yes" in checkBoxAValue.collect{it.toString()})
{
issueKeys.add("${linkedIssue.key}")
}
}
}
linkManager.getInwardLinks(issue.id).each{
def linkedIssue = it.sourceObject
def checkBoxAValue = linkedIssue.getCustomFieldValue(checkBoxA)
if(it.issueLinkType.name == "Related to RoadMap")
{
//Checks that "Yes" is a selected value for check box A
if("Yes" in checkBoxAValue.collect{it.toString()})
{
issueKeys.add("${linkedIssue.key}")
}
}
}
Try that out and see if that get's what you're looking for! :D
Best of Luck,
Aidan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's working! thank you Aidan,
I have been calling "destinationObject" for InwardLinks method, and now realized that we need to call SoureObject.
Regards,
Suresh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome! No problem Suresh! :D
The methods are a little tricky to work with at first, so I understand the confusion :)
Could you please accept this answer so that it will appear as answered for others who may be having similar issues?
Glad I could help!
Aidan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aidan Derossett [Adaptavist] Can we sort the linked issue keys list based on issue numbers?
if(issueKeys.size() > 0)
{
return issueKeys.join(',')
}
else
{
return null
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey there,
You absolutely can :D
Using Groovy, you can do some sorting magic on the issueKeys array:
issueKeys.sort{a, b ->
a.split("-")[1] <=> b.split("-")[1]
}
I think that should do it. Give it a go and make sure nothing explodes haha.
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.
NICE!!!
No problem, let me know if you have any other troubles :D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suresh,
This can be done easily with an add on called Scriptrunner. Please go through the documentation for it and you will be able to understand on how to do it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Praveen,
I have started as below, first I am trying return only linked issue to the script field.The following code returning only one issue, How to return all linked issues those related to linktype.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.UpdateIssueRequest
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def linkedIssue;
issueLinkManager.getInwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Related To RoadMapItem") {
linkedIssue = issueLink.getSourceObject()
}
}
return linkedIssue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again,
The below code will return the list of issues, if you need the objects of them you have to iterate the list.
def linkedIssues=issueLinkManager.getInwardLinks(issue.id)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am trying as following.But it is returning no result.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def linkedIssues
def keys
linkedIssues=issueLinkManager.getInwardLinks(issue.id)
issueLinkManager.getInwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Related To RoadMapItem") {
for(Iterator outIterator = linkedIssues.iterator(); outIterator.hasNext();){
IssueLink issueLink2 = (IssueLink) outIterator.next();
linkedIssues = issueLink2.getSourceObject().getKey();
StringBuilder builder = new StringBuilder();
for(String s : linkedIssues) {
builder.append(s);
}
keys = builder.toString();
}
}
}
return keys
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Suresh:
In JIRA there can be outbound links and inward links.
If inwardlinks isn't getting you what you want, use the outwardlinks like so:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def linkedIssues
def keys
linkedIssues=issueLinkManager.getOutwardLinks(issue.id)
issueLinkManager.getInwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Related To RoadMapItem") {
for(Iterator outIterator = linkedIssues.iterator(); outIterator.hasNext();){
IssueLink issueLink2 = (IssueLink) outIterator.next();
linkedIssues = issueLink2.getSourceObject().getKey();
StringBuilder builder = new StringBuilder();
for(String s : linkedIssues) {
builder.append(s);
}
keys = builder.toString();
}
}
}
return keys
Hope this helps:
Dyelamos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Suresh,
Please try this
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
//def linkedIssues
def keys
//linkedIssues=issueLinkManager.getInwardLinks(issue.id)
def linkedIssues = issueLinkManager.getInwardLinks(issue.getId())if (linkedIssues!=null){
for(int a=0; a<linkedIssues.size(); a++){
if (linkedIssues[a].issueLinkType.name == "Related To RoadMapItem"){
IssueLink issueLink2 = (IssueLink) outIterator.next();
linkedIssues = issueLink2.getSourceObject().getKey();
StringBuilder builder = new StringBuilder();
for(String s : linkedIssues) {
builder.append(s);
}
keys = builder.toString();
}
}
}
return keys/*issueLinkManager.getInwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Related To RoadMapItem") {
for(Iterator outIterator = linkedIssues.iterator(); outIterator.hasNext();){
IssueLink issueLink2 = (IssueLink) outIterator.next();
linkedIssues = issueLink2.getSourceObject().getKey();
StringBuilder builder = new StringBuilder();
for(String s : linkedIssues) {
builder.append(s);
}
keys = builder.toString();
}
}
}*/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Suresh.
What if you remove the if clause:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def linkedIssues = issueLinkManager.getOutwardLinks(issue.id)
def keys
issueLinkManager.getInwardLinks(issue.id).each {issueLink ->
log.debug issue.issueLinkType.name
for(Iterator outIterator = linkedIssues.iterator(); outIterator.hasNext();){
IssueLink issueLink2 = (IssueLink) outIterator.next()
linkedIssues = issueLink2.getSourceObject().getKey()
StringBuilder builder = new StringBuilder()
for(String s : linkedIssues) {
builder.append(s)
}
keys = builder.toString()
}
}
return keys
Does this return anything at least?
A common scriptbuilding case, would be for you to use a few issues as an example, and using the console, debug the simplest case, and then move up in complexity until you have what you want. Even us "experts" don't get what we want the first time we try.
Cheers!
DYelamos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Pavan, DYelamos,
I am getting object like as below and trying to get the key from below objects. I do not find any method to getkey from linked issue object.am i missing any this here.
[com.atlassian.jira.issue.link.IssueLinkImpl@a64103b[id=140208,sourceId=149223,destinationId=149229,issueLinkType=10800],
com.atlassian.jira.issue.link.IssueLinkImpl@50487581[id=140210,sourceId=147897,destinationId=149229,issueLinkType=10800]]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Greetings all,
I have a quite same question, but not on custom fields. On ranking.
I'll be grateful for your help.
https://community.atlassian.com/t5/Questions/How-to-get-list-of-Linked-issues-which-are-quot-is-blocked-by/qaq-p/777864
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Surreh:
That happens because links do not have keys, they have the JIRA numeric ID for issues. The link object does not contain two issues, but a reference to both of them in form of their numeric id.
What you need to do after you get the link is to do a:
IssueManager.getIssue(destinationId)
IssueManager.getIssue(sourceId)
That will fetch the right info for you.
Cheers!
Dyelamos
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.