Hello Team,
Currently, I have noticed that I can create an epic issue type with the same epic name across all the projects.
I want to restrict the same. I want each user to give an epic name differently for each epic issue type. Jira should not create a duplicate epic if any other epic has the same name epic exist in the project
Can somebody help to restrict the same?
Thanks in Advance.
Shubhanshu
Hi @Shubhanshu Trivedi ,
you can do that using a validator on create issue workflow event.
ScriptRunner allows you to add a scripted validator with that behaviour.
Hope this helps,
Fabio
Hello @Fabio Racobaldo _Herzum_ ,
Do you have written any such validator script which I use in my project?
Regards,
Shubhanshu Trivedi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Shubhanshu Trivedi ,
try this scripted validator :
import java.util.List;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.search.SearchException;
import com.atlassian.jira.issue.search.SearchResults;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.web.bean.PagerFilter;
import com.opensymphony.workflow.InvalidInputException;
SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField epicNameCF = (customFieldManager.getCustomFieldObjectsByName("Epic Name")).iterator().next();
String currentEpicName = issue.getCustomFieldValue(epicNameCF).toString();
String query = "project = "+issue.getProjectObject().getKey()+" AND \"Epic Name\" = \""+currentEpicName+"\"";
SearchService.ParseResult parseResult = searchService.parseQuery(authContext.getLoggedInUser(), query);
try {
SearchResults results = searchService.search(authContext.getLoggedInUser(), parseResult.getQuery(),
PagerFilter.getUnlimitedFilter());
List<Issue> epics = results.getResults();
if(epics.size()>0){
throw new InvalidInputException("Epic Name already existing!");
}
} catch (SearchException e) {
throw new InvalidInputException("Epic Name already existing!");
}
Please let me know if it works for you.
You can also change the error message at your convenience.
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Fabio Racobaldo _Herzum_ ,
Thanks a lot. The above code worked successfully in the project. I need one more suggestion from you.
Similar way we have such a script where we are creating a sub-task and updating a summary for the sub-tasks issue.
For example-
if Parent JIRA Summary = Parent-Task Summary The subtask has Variant=XYZ, Type = ABC, Sub-Task Summary field = Testing123
then the Subtask Summary should be : [XYZ][ABC] - Parent-Task Testing123
Code is like--
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
Issue issue = issue
Logger logger = log
if (issue.isSubTask()) {
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField variantCF = customFieldManager.getCustomFieldObjectsByName("Variant").first()
CustomField typeCF = customFieldManager.getCustomFieldObjectsByName("Type").first()
List<Option> variant = issue.getCustomFieldValue(variantCF)
StringBuilder variantString = new StringBuilder("[")
variant?.each {
variantString.append("${it.getValue()},")
}
if(variantString.toString().trim().endsWith(",")){
String temp = variantString.toString()
variantString.replace(temp.lastIndexOf(","), temp.lastIndexOf(",") + 1, "" );
}
variantString.append("]")
String summary = variantString.toString()
Option type = issue.getCustomFieldValue(typeCF)
if(type){
summary += "[${type.getValue()}]"
}
logger.info(issue.getParentObject().getKey())
Issue parentIssue = issue.getParentObject()
summary += " - ${parentIssue.getSummary()} "
logger.info(summary)
issue.summary = summary
updateIssue(issue)
}
void updateIssue(Issue issue) {
MutableIssue issueToUpdate = (MutableIssue) issue
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
issueManager.updateIssue(user, issueToUpdate, EventDispatchOption.DO_NOT_DISPATCH, false)
}
Above code is giving me output - [XYZ][ABC] - Parent-Task
not this
[XYZ][ABC] - Parent-Task Testing123
can you please help me to find the issue in the above code?
Regards,
Shubhanshu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Shubhanshu Trivedi ,
when your script runs, probably parentObject link is not set yet. Please, move that post function after event Issue create originally and try again (you can update post functions orders).
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Fabio Racobaldo _Herzum_ ,
I already tested the same. I am getting the same summary in the sub-task issue like [XYZ][ABC] - Parent-Task.
Shubhanshu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this code :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
Issue issue = issue
Logger logger = log
if (issue.isSubTask()) {
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField variantCF = customFieldManager.getCustomFieldObjectsByName("Variant").first()
CustomField typeCF = customFieldManager.getCustomFieldObjectsByName("Type").first()
List<Option> variant = issue.getCustomFieldValue(variantCF)
StringBuilder variantString = new StringBuilder("[")
variant?.each {
variantString.append("${it.getValue()},")
}
if(variantString.toString().trim().endsWith(",")){
String temp = variantString.toString()
variantString.replace(temp.lastIndexOf(","), temp.lastIndexOf(",") + 1, "" );
}
variantString.append("]")
String summary = variantString.toString()
Option type = issue.getCustomFieldValue(typeCF)
if(type){
summary += "[${type.getValue()}]"
}
logger.info(issue.getParentObject().getKey())
Issue parentIssue = issue.getParentObject()
summary += " - ${parentIssue.getSummary()} "
logger.info(summary)
MutableIssue mIssue = (MutableIssue) issue;
mIssue.setSummary(summary);
updateIssue(issue)
}
void updateIssue(MutableIssue issueToUpdate) {
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
issueManager.updateIssue(user, issueToUpdate, EventDispatchOption.DO_NOT_DISPATCH, false)
}
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.
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.