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
@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
}
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's work for me as is .. This line work for validator only.
The answer resolved your issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.