The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Deleted user
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 • Deleted user likes this