Forums

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

Scriptrunner: Listener to set time estimates to a default value when they are not empty

Reno February 21, 2022

Hello,

I am trying to set up a custom listener on issue creation that checks if the original and remaining estimates are empty, and in that case, set both to "1m".

I tried some solutions that I found in the community but I did not manage to get them working as expected.

Can anyone help me? What methods should I use to get and set both values?

Thank you in advance!

1 answer

1 accepted

1 vote
Answer accepted
Aditya Sastry
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.
February 21, 2022

Hi Reno,

The below code should work for your need.  

Please also consider this answer as accepted if this is the solution you were looking for. That will make it more traceable for users in the future if they are facing the same issue.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import org.apache.log4j.Category
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.bc.issue.IssueService

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
IssueManager im = ComponentAccessor.getIssueManager()
def issue = issue
//def issue = im.getIssueObject("ABR-39")
IssueService issueService = ComponentAccessor.getIssueService()


if (!issue.getEstimate() && !issue.getOriginalEstimate()){

def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setOriginalAndRemainingEstimate('1m','1m')

def updateValidationResult = issueService.validateUpdate(loggedInUser, issue.id, issueInputParameters)
if (updateValidationResult.isValid()) {
// Validate the update
def issueResult = issueService.update(loggedInUser, updateValidationResult)
}
}
//log.info(issue.getEstimate())
//log.info(issue.getOriginalEstimate())
//log.info(issue.getTimeSpent())

 

Thanks,

Aditya

 

 

Reno February 22, 2022

Thank you so much Aditya, it works as expected! 

This is also very helpful to get me started with other scripts, since I am still struggling with the Jira API.

Like Aditya Sastry likes this

Suggest an answer

Log in or Sign up to answer