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

How to use Scriptrunner to update the Issue Type scheme ? Edited

I want to update the Issue Type Link scheme on the newly created projects. Can someone please help me with using Scriptrunner script for updating the issue type link scheme ? Maybe like use a post function on the workflow. 

We have an automated project creation step. When an user requests for a new project through our Service desk its automatically created.

1 answer

Hello @Aisha M ,

Could You please clarify what You mean on 'Issue Type Link scheme'? I know about 'Issue linking' but it is scheme per system not per project. Could You please explain more details and  provide screen?

Best regards,
Andrew

Hi @Andrew , Thank you for the comment.

There is an option called LINK SCHEMES available under the adminstration panel - Category - LINKS

We have a LINK SCHEME for each each issue type. An combination of all these is a ISSUE TYPE LINK SCHEME. There is a default. So, we want all the newly created projects to have this instead of the DEFAULT ISSUE TYPE LINK SCHEME

I suppose You mean this plugin https://marketplace.atlassian.com/apps/1214172/extended-schemes-for-jira?hosting=server&tab=overview

https://devpost.com/software/link-schemes-for-jira

I'm right?

If yes, that mean You try use script runner make changes in some 3rd party plugin. I'm not sure that it is possible because I not found something REST API for that plugin. I recommend ask support team of that plugin.

Best regards,

Andrew

Yes @Andrew , that is exactly the plugin being used. So, you think we cantedit a scheme that way using Scriptrunner ?

Thank you !

Yep, scriptrunner used next java API https://docs.atlassian.com/software/jira/docs/api/7.13.8/ It is base of jira application, 3rd party java api not placed here and I'm not sure that possible reach java API of the 3rd party. As workaround I thought use rest API, but I not found some rest API for 'extend scheme' plugin.

Again, You can try ask support team of the plugin, maybe they can help You. I have no experience with the 'extend schemes' plugin.

Best regards,

Hi @Andrew ,

Can you help me with the below existing Scriptrunner script.

I use the below script to capture the dates of the Epic Due Date and post the farthest date at the Program Epic Due Date field (scripted field). If any of the Due Date in the Epic is empty, then the scripted field at the Program Epic returns empty.

The script is working fine, but considers ALL of the epics associated with the Program Epic. Can you please help me modify the script so that ONLY the child of the Program Epic is considered and no other links.

 

import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp

def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
def issueLinks = allOutIssueLink?.findAll() {it.getDestinationObject().getIssueType().getName() == "Epic"}
def farthestDate


for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()
if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}

def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()));
issueLinks = allInIssueLink?.findAll() {it.getSourceObject().getIssueType().getName() == "Epic"}

for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()

if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}

return farthestDate

Hi @Andrew , Can you please help me with the above script :(

Like Andrew likes this

Hello @Aisha M ,

Sorry for long time reaction, I was busy. I hope I right understand direction in which links should be updated. 

import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def farthestDate
def issueLinks

//comment next section for use only inward links. From parent to child
//start section OUTWARD
/*
def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
issueLinks = allOutIssueLink?.findAll() {it.getDestinationObject().getIssueType().getName() == "Epic"}




for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()
if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
*/
//end section OUTWARD


//comment next section for use only inward links. From parent to child
//start section INWARD
def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()));
issueLinks = allInIssueLink?.findAll() {it.getSourceObject().getIssueType().getName() == "Epic"}

for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()

if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}
//end section INWARD

return farthestDate

Your code consist from two parts. First for outward links and second for inward links. As You can see I just disable the first part.  If I made wrong parent-child direction You need just disable the second part and enable first part. I write comments in code for that.

Moreover I would like recommend You create new links type, because standard 'relate to' link not clarity for user. For example, in picture below 'relates to' not say that TEST-6 is parent or child? 
Capture.PNGSo, I've made new links and set different name to inward and outward link. After I changed date in the current ticket the script affect to TEST-6.

Best regards,
Andrew

Hi @Andrew , Thank you sooo soo much !!! I will test this out now.

Actually my manager wants the script to work ONLY if the Epic is a child of the Program Epic. 

The script should not consider the Epic Due date if the linking is of any other type like relates or clones or duplicates etc

Hi @Andrew , I tried out the  script and yes, it works with outward & inward links.

But, I want the script to work ONLY if the Epic is a child. No other link should be considered. Will that be possible ?

Thank you 

I suppose it is possible, but I should understand criteria to identify that the current epic is the child.


'The script should not consider the Epic Due date if the linking is of any other type like relates or clones or duplicates etc' 

- so, I suppose You have some specific link type for that? 

'Epic is a child of the Program Epic'

 - Do You have two epic types? 

Best regards,

Hi @Andrew , Yes, the Epic  issue type is child of the Program Epic.

The only link they want to consider is , "Child of Custom Link" . . which is the name we have to link the Epics to the Program Epic.

You think its possible ?

Thanks

So, as I understand: due date of the Program epic should affect to 'pr.due date' of the epic by only link name 'Child'('parent' from epic side).

 

import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def farthestDate
def issueLinks

def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))



def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()));
issueLinks = allInIssueLink?.findAll() { (it.getSourceObject().getIssueType().getName() == "Program Epic") && (it.getIssueLinkType().getInward() == "Parent") }

for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()

if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}

return farthestDate

For that I've change condition: (it.getSourceObject().getIssueType().getName() == "Program Epic") && (it.getIssueLinkType().getInward() == "Parent", as You see I use type name 'Program Epic' and link type name 'Parent'.

For example in the current program epic affect only to epic 'test-4'

Capture.PNGBest regards,

Andrew

Hi @Andrew  , I tried the above script. But its not working for me. In-fact, no date is available.

I replaced "Parent" with "Parent of Custom Link" , as that is how the link name is in our project.

Also, there is no mention on Epic in the above script, then how does the scripted field pull the farthest Due Date value of Epic and display at Program Epic ?

I suppose we are confusing in parent-child relation.

I simplified condition.

import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def farthestDate
def issueLinks

def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))



def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()));
issueLinks = allInIssueLink?.findAll() { it.getIssueLinkType().getInward() == "Parent" }

for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()

if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}

return farthestDate

If this also not working, could You please check screen of next settings 'linking':Capture.PNG

'Parent' placed in Inward column?

Hi @Andrew ,

The above script din work as well. It did not show any date at all.

I checked like you have asked,

PARENT OF CUSTOM LINK - Outward

CHILD OF CUSTOM LINK - Inward.

 

Also few more description,

The Due Date field is the regular JIRA field available at the Epic issue

Scripted Due Date (Scripted filed) is added to the Program Epic issue screen. So, its visible only at Program Epic issue type.

Then, in the issue hierarchy, we have Program Epic and below that we have Epic

Scenario - The scripted field pulls the farthest date from the Epic and displays at the Program Epic. If any one of the regular Due Date of Epic is empty, then the scripted field returns empty at Program Epic too.

Hope the helps . .Thank for trying to help. I'm really grateful for helping me

Hi @Andrew , Your thoughts on the above comment please :)

Could You please check next code?

import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def farthestDate
def issueLinks

def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
issueLinks = allOutIssueLink?.findAll() { (it.getDestinationObject().getIssueType().getName() == "Epic") && (it.getIssueLinkType().getOutward() == "Parent") }

for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getDestinationObject().getDueDate()

if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}

return farthestDate

or 

import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
import java.sql.Timestamp
def farthestDate
def issueLinks

def allInIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId()));
issueLinks = allInIssueLink?.findAll() { (it.getSourceObject().getIssueType().getName() == "Epic") && (it.getIssueLinkType().getInward() == "Child") }

for(IssueLink issueLink : issueLinks){
def dueDate = issueLink.getSourceObject().getDueDate()

if (dueDate == null){
return null
}
else if (farthestDate == null){
farthestDate = dueDate
}
else if (dueDate?.after(farthestDate)){
farthestDate = dueDate
}
}

return farthestDate

I hope one of them will work as needed.

Best regards,

Thank you sooo much @Andrew  !! The first one works great. Thank you a million times for taking the time to help me :)

Like Andrew likes this

Hi @Andrew , Hope you are well :) I just some question your script and hope you can help.

The script was working great in our DEV env. But, its not working in QA. I'm getting the below error,

2020-06-15 09:45:13,194 ERROR [customfield.GroovyCustomField]: *************************************************************************************
2020-06-15 09:45:13,194 ERROR [customfield.GroovyCustomField]: Script field failed on issue: ATLAS-540, field: PE Scripted Due Date
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script165.groovy: 16: unable to resolve class IssueLink 
 @ line 16, column 37.
   def allOutIssueLink = new ArrayList<IssueLink>(ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId()))
                                       ^
Script165.groovy: 19: unable to resolve class IssueLink 
 @ line 19, column 1.
   for(IssueLink issueLink : issueLinks){
   ^
2 errors

Also, one more thing is, in QA we have enabled this plugin called saFe EPIC to Feature translator. So, this Plugin helps translate the issue name to Feature. 

 

Please help. Thank yo.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

1,666 views 10 16
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