Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,367,806
Community Members
 
Community Events
168
Community Groups

Automate rule to create Bug issue type any time a sprint is created

I would like to create a Automated  rule to trigger a Bug issue type any time a sprint is created. The bug issue type Should be part of the sprint and should go inside the sprint\be part of the sprint and not to pulled from the backlog.

I need a bug issue type to be created with  certain fields . I would also want the Bug issue type to use the  customized work flow I currently have for bug issue type (In my customized work flow condition  I have added post functions, Subtask blocking condition, validators etc).

1 answer

1 vote

Hey @Garden16_ 

Please check this out this thread which has similar use case.

You have to use "Custom Listeners" and use "SprintCreatedEvent"

Please check the script to be written here, you may have to modify bit to add fields and fill their values to get it working:

https://community.atlassian.com/t5/Jira-questions/Sprint-Create-Event/qaq-p/667714

 

Regards,

Vishwas

Vishwas Community Leader Jan 09, 2022

Just checked out the script too, it worked and created a "Bug" issue and added to the Sprint also

this listener stopped working . I getting the following error

 

 

 

 

 

7 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2022-01-19 10:17:49,888 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.greenhopper.api.events.sprint.SprintCreatedEvent, file: null
com.atlassian.jira.exception.CreateException: Error occurred while creating issue through workflow:
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:583)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:487)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(DefaultIssueManager.java:597)
at com.atlassian.jira.issue.managers.RequestCachingIssueManager.createIssueObject(RequestCachingIssueManager.java:201)
at com.atlassian.jira.issue.IssueManager$createIssueObject$2.call(Unknown Source)
at Script61.run(Script61.groovy:21)
Caused by: [InvalidInputException: [Error map: [{assignee=Bug must be assigned }]] [Error list: [[]]]
at com.onresolve.scriptrunner.canned.jira.utils.ScopeAwareExceptionMapper.convertException(ScopeAwareExceptionMapper.groovy:26)
at com.onresolve.scriptrunner.canned.jira.utils.ScopeAwareExceptionMapper$convertException.call(Unknown Source)
at com.onresolve.jira.groovy.GroovyValidator.validate(GroovyValidator.groovy:56)
at com.atlassian.jira.workflow.SkippableValidator.validate(SkippableValidator.java:45)
at com.opensymphony.workflow.AbstractWorkflow.verifyInputs(AbstractWorkflow.java:1466)
at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1167)
at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:606)
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:754)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:578)
... 5 more

This is my code 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.PriorityManager

def issueFactory = ComponentAccessor.getIssueFactory()
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def newIssue = issueFactory.getIssue()
def project = ComponentAccessor.projectManager.getProjectByCurrentKey("QBT")
def bugIssueType = ComponentAccessor.constantsManager.getAllIssueTypeObjects().find { it.getName() == "Bug" }
def highPriority = ComponentAccessor.getComponent(PriorityManager).getPriority("High")
def sprintCF = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Sprint")

newIssue.setSummary("summary")
newIssue.setProjectObject(project)
newIssue.setIssueType(bugIssueType)
newIssue.setPriority(highPriority)
newIssue.setCustomFieldValue(sprintCF, [event.sprint]) //add the issue to the sprint that just started and triggered the event
//... any other fields

Map<String,Object> newIssueParams = ["issue" : newIssue] as Map<String,Object>
ComponentAccessor.issueManager.createIssueObject(loggedInUser, newIssueParams)

Can you look into the log 

Vishwas Community Leader Jan 19, 2022

Did you have assignee as a mandatory field on issue creation screen for QBT Project ?

From error log I could see that issue creation failed because of assignee field, so in the script modify to add a default assignee, that should fix the issue.

when ever the sprint is created an issue type gets created and it  displays  display 0 issues. although  an issue type is created . How to show issue type on the screen.

 

 

 

0 issues displayed.PNG

when ever the sprint is created an issue type gets created and it  displays  display 0 issues. although  an issue type is created . How to show issue type on the screen.

Please suggest answer

Vishwas Community Leader Jan 24, 2022

@Garden16 

Let me check this working, actually in my case issue created gets directly added to the sprint.

newIssue.setCustomFieldValue(sprintCF, [event.sprint]) //add the issue to the sprint that just started and triggered the event

The above code should add the issue to the sprint 

It does.But if you look at the screen shot I put , it shows 0 issues

although is created.

 

I wanted to add date field in the issue that displays the date issue was created 

 

howdo I get it in code

please look a the attached image0 issues displayed.PNGplease look a the attached image 

Im checking on my end. It added to the sprint too. I created 2 sprints and it worked both times.

Please see this.

Picture1.png

My code in Listeners (Custom Listeners)

Listeners.png

 

Code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.PriorityManager

def issueFactory = ComponentAccessor.getIssueFactory()
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def newIssue = issueFactory.getIssue()
def project = ComponentAccessor.projectManager.getProjectByCurrentKey("TSP")
def bugIssueType = ComponentAccessor.constantsManager.getAllIssueTypeObjects().find { it.getName() == "Bug" }
def highPriority = ComponentAccessor.getComponent(PriorityManager).getPriority("High")
def reporter = ComponentAccessor.userManager.getUserByKey("auser")
def sprintCF = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Sprint")

newIssue.setSummary("A summary")
newIssue.setProjectObject(project)
newIssue.setIssueType(bugIssueType)
newIssue.setPriority(highPriority)
newIssue.setReporter(reporter)
newIssue.setCustomFieldValue(sprintCF, [event.sprint]) //add the issue to the sprint that just started and triggered the event
//... any other fields

Map<String,Object> newIssueParams = ["issue" : newIssue] as Map<String,Object>
ComponentAccessor.issueManager.createIssueObject(loggedInUser, newIssueParams)

Let me try it again. Also wanted to know how i can get current sprint name in the summary  feild

example -  

newIssue.setSummary(" Issue type created for '$Sprint name')

I also have custom field name Issue logged date . I want to populate the sprint create date (current date) in this field when ever the issue created.

HHow do I do this?
Vishwas Community Leader Jan 25, 2022

Let me try these 2 things and get back

Your code is working and creating the issue . But on the screen dont  know why  it is showing 0 issues instead of 1 issue 

Vishwas Community Leader Jan 25, 2022

Great !!

Go inside issue and see if it is part of the new Sprint ?

On other two things I'm unable to get the date and sprint name at the moment

Like Garden16 likes this

Its created and part of the new sprint. But why does it show 0 issues on the screen. I tried refreshing the screen. Still is shows 0 issues . Did you see my screen shot? It  says 0 issues next to the blue color icon. I wanted to know if there is a fix for it.

Vishwas Community Leader Jan 25, 2022

Hmm, i saw the screenshot. Don't know what could be the issue. Can you check what is the query written on the board. In Backlog --> go to configure board -> General.

Maybe the board filter query can be excluding this issue created.

Please try reaching to adaptvist support team they can analyze further on the other two requirements..

https://productsupport.adaptavist.com/servicedesk/customer/portal/2

My configure Board shows the following query. It shows the issue type that got created . But on the Board it shows 0 issues although there is an issue created .

when I click on the blue icon I see the following results. But the issue count shows 0 issues although there is an automated issue created .

Here are the results of the query board .

Here is the query boardconfigure board.PNG

I updated the query  . Still its showing 0 issues 

 

project = ABC AND issuetype = "BUG" AND created >= -1w ORDER BY cf[10106] ASC, assignee ASC, created DESC

Vishwas Community Leader Jan 31, 2022

Query looks fine. both queries are okay.

Are the other issues created in backlog and added to sprint shows in number.

not able to get what is the issue, please check with support team.

I was able to add issue type manually and it showed me the count as 1 issue type. But in fact there were two issue types in the sprint .One that was created automatically  via the listener and the other that I created manually. I don't know why the issue count is getting displayed anytime the issue created via the custom listener .

issues on board.PNG

Any digestions would be helpful

suggestion's * would be helpful

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events