Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner Adding stories even when epic is in Done Status

Aishwarya Rajan April 23, 2018

Hello,

In JIRA its a known issue that we can add stories to the epic even if its resolved or "Done". Is there any way to disable this feature through scripts..behaviors??? By utilizing the epic link or  parent link property??? Please advise

3 answers

0 votes
Aishwarya Rajan May 11, 2018

@Neta Elyakim this is my changed script basically:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException

def customFieldManager = ComponentAccessor.getCustomFieldManager()

//Issue issue = getIssueContext() as Issue
Issue currentIssueContext = getIssueContext() as Issue

def issueManager = ComponentAccessor.getIssueManager()

Issue currentIssue = issueManager.getIssueObject(""+currentIssueContext.getKey())


if(currentIssue.getIssueType().getName() == "Story"){
String epic_link = currentIssue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName('Epic Link'));
List<Issue> issues = getJQLsearchResult(/"Epic Name" = '/+epic_link + /'/)

def desc = getFieldById("description");
desc.setHelpText(""+issues);

if (issues.size()>0) {
issues.each { iss ->
if(iss.getStatus().name == "Done"){
def invalidInputException = new InvalidInputException("The Epic you have chosen is in status Done please choose a different one")
return null
}
}
}
}
List<Issue> getJQLsearchResult(String jqlSearch){
def searchService = ComponentAccessor.getComponentOfType(SearchService.class)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
List<Issue> resultIssue
def results = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
resultIssue = results.getIssues()
return resultIssue
}

0 votes
Neta Elyakim
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 2, 2018

You can add validator on create screen (for Stories WF for example) that check the field "Epic link" -> get the issue object of the "Epic link" - check his status- if "Done" then you trow an error that said- "The Epic you have chosen is in status Done please choose a different one"

You can try this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException

def customFieldManager = ComponentAccessor.getCustomFieldManager()

if(issue.getIssueType().getName() == "Story"){
String epic_link = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName('Epic Link'));
List<Issue> issues = getJQLsearchResult(/"Epic Name" = '/+epic_link+/'/)

if (issues.size()>0) {
issues.each { iss ->
if(iss.getStatus().name == "Done"){
invalidInputException = new InvalidInputException("The Epic you have chosen is in status Done please choose a different one")
return null
}
}
}

}
List<Issue> getJQLsearchResult(String jqlSearch){
def searchService = ComponentAccessor.getComponentOfType(SearchService.class)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
List<Issue> resultIssue
def results = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
resultIssue = results.getIssues()
return resultIssue
}
Aishwarya Rajan May 11, 2018

@Neta Elyakim I tried to execute your script as it it but its not making any of the expected changes as we intend to.. also I wanted to know what this line:

also can you put some light on this exception class :

import com.opensymphony.workflow.InvalidInputException

 

i had to declare the var with def 

def invalidInputException = new InvalidInputException("The Epic you have chosen is in status Done please choose a different one") as scriptrunner showed error

where as in your code it was just this:

invalidInputException = new InvalidInputException("The Epic you have chosen is in status Done please choose a different one")

Neta Elyakim
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2018

It's work for me as is .. This line work for validator only.

The answer resolved your issue?

0 votes
miikhy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2018

Hi there,

Hope you're well!

I've "solved" a similar case once by using an App (nFeed, https://marketplace.atlassian.com/plugins/com.valiantys.jira.plugins.SQLFeed/server/overview - you can use any other SQL related App in fact) to create a customfield with a dropdown offering only "not Done" epics. Once a value was selected in it, the value was copied in the epic link field (which was not on edit/create screens, just in view screen). That's kind of an overkill but it was working well!

Hope this helps!

Suggest an answer

Log in or Sign up to answer