Forums

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

Please add preventing to go above 2w for Original estimates. People have to ensure <2w for a right

mummareddy supriya
Contributor
September 4, 2023

using this script for scriptrunner-behaviours 

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.ErrorCollection
import java.math.BigInteger

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("PIQ-53183") as MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def estimatedEffortFieldName = "Estimated Effort"
def estimatedEffortField = customFieldManager.getCustomFieldObjects(issue).find { it.name == estimatedEffortFieldName }
def estimatedEffortValue = issue.getCustomFieldValue(estimatedEffortField) as String

if (estimatedEffortValue) {
    // Extract weeks, days, and hours from the estimated effort string
    def weeks = estimatedEffortValue.find(/(\d+)w/)
    def days = estimatedEffortValue.find(/(\d+)d/)
    def hours = estimatedEffortValue.find(/(\d+)h/)

    // Calculate the total estimated effort in hours
    BigInteger totalHours = BigInteger.ZERO

    if (weeks) {
        totalHours += weeks[1] as BigInteger * 7 * 24
    }
    if (days) {
        totalHours += days[1] as BigInteger * 24
    }
    if (hours) {
        totalHours += hours[1] as BigInteger
    }

    // Check if the total estimated effort exceeds 2 weeks (336 hours)
    if (totalHours > BigInteger.valueOf(336)) {
        issue.setCustomFieldValue(estimatedEffortField, null)
        ErrorCollection errorCollection = ComponentAccessor.getComponent(ErrorCollection)
        errorCollection.addError(estimatedEffortField.getId(), "Estimated effort exceeds 2 weeks (336 hours).")
        issue.getErrorCollection().addAllErrorMessages(errorCollection.getErrorMessages())
    }
}
i'm getting error as 
[Static type checking] - Cannot find matching method java.lang.Object#addAllErrorMessages(java.util.Collection<java.lang.String>). Please check if the declared type is correct and if the method exists. 
if any one know ,please help me on this script 

0 answers

Suggest an answer

Log in or Sign up to answer