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
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 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.ComponentAccessorimport com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.web.bean.PagerFilterimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.jira.issue.Issueimport com.opensymphony.workflow.InvalidInputExceptiondef 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}
@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 this is my changed script basically:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.web.bean.PagerFilterimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.jira.issue.Issueimport com.opensymphony.workflow.InvalidInputException
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//Issue issue = getIssueContext() as IssueIssue 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> resultIssuedef results = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())resultIssue = results.getIssues()return resultIssue}
It's work for me as is .. This line work for validator only.
The answer resolved your issue?
It looks like you're new here. Sign in or register to get started.