This article is for Tempo for Data Center.
With the script listener you can catch events related to Timesheet approvals. Timesheet approval events are “submit, approve, reject”.
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.event.api.EventListener
import com.atlassian.event.api.EventPublisher
import com.tempoplugin.timesheet.approval.api.Approval
import com.tempoplugin.timesheet.approval.api.event.ApprovalEvent
import com.tempoplugin.timesheet.approval.api.event.ApprovalCreatedEvent
import com.tempoplugin.platform.api.event.Event
import org.apache.log4j.Level
import org.apache.log4j.Logger
def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)
@WithPlugin("is.origo.jira.tempo-plugin")
ApprovalEvent tempoapprovalevent = event
myLog.info("${tempoapprovalevent} detected")
if(tempoapprovalevent.approval.action) {
myLog.info("Eventtype: ${tempoapprovalevent.approval.action} detected")
// submit, approve, reject
switch(tempoapprovalevent.approval.action){
case "submit":
myLog.info("Timesheet of ${tempoapprovalevent.approval.actorKey} has been submitted!")
break
case "approve":
myLog.info("Timesheet of ${tempoapprovalevent.approval.actorKey} has been approved!")
break
case "reject":
myLog.info("Timesheet of ${tempoapprovalevent.approval.actorKey} has been rejected!")
break
}
}
The timesheet approval event casts an object with the following parameters
{
id=108,
userKey=beverly,
actorKey=john,
reviewerKey=john,
status=approved,
period=0121,
dateFrom=2021-01-01,
dateTo=2021-01-31,
periodType=BILLING,
periodView=PERIOD,
reason=Great job!,
workedTime=0,
submittedTime=0,
requiredTime=576000,
action=approve
}