/
Check value of a duration attribute can't be larger than "Time spent" field

Check value of a duration attribute can't be larger than "Time spent" field

This script check value of “Billable time” attribute (a duration worklog attribute) can’t be larger than “time spent” field of the worklogs.

import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.security.JiraAuthenticationContext; import com.atlassian.jira.security.roles.ProjectRoleManager; import com.deniz.jira.worklog.services.attr.AttrTypeService; def authenticationContext = ComponentAccessor.getJiraAuthenticationContext(); //We need to load WorklogPRO classes differently using getOSGiComponentInstanceOfType def attrTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(AttrTypeService.class); def billableTimeAttr = attrTypeService.getAttrTypeWithName("Billable time").get(); if (billableTimeAttr == null) { return; //there is no "billable time" attribute } def valueForBillableTime = worklogAttributes.get(billableTimeAttr.getID()); println("worklogAttributes:" + worklogAttributes); //attribute values are integer corresponding to names println("timeSpent:" + worklog.getTimeSpent()) //time spent is in seconds println("valueForBillableTime:" + valueForBillableTime) if (valueForBillableTime == null) { return; //no bllable time specified } println(valueForBillableTime.getClass()); if (Long.parseLong(valueForBillableTime) > worklog.getTimeSpent()) { return "billable time can't be larger than time spent"; }