Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

You can execute execute a Groovy script just before usual handling of timesheet submission/revoke and stop the submission process by returning an error message. Returned message will be shown to user submitting/revoking his/her timesheet. If you don’t return anything from this script normal submission workflow will run and if everything is okey, user’s timesheet will be submitted/revoked.

Within this script you can access Jira services, WorklogPRO services and services from other plugins. You can use TimesheetApprovalRequest parameter to access values submitted by the user. Following script uses WorklogHelper service to get daily required work hours and daily actual work hours of the user for the timesheet period and checks the differences for totals. If user is submitted less than required work hours, it rejects timesheet submission.

import com.atlassian.jira.component.ComponentAccessor;
import com.deniz.jira.worklog.utils.*;
//We need to load WorklogPRO classes differently using getOSGiComponentInstanceOfType
def worklogHelper = ComponentAccessor.getOSGiComponentInstanceOfType(WorklogHelper.class);

//please enable logging for package "com.deniz.jira.worklog.scripting" from Administration/System/Logging and Profiling
log.debug("userKey, {}", timesheetApprovalRequest.userKey);
log.debug("action, {}", timesheetApprovalRequest.action);
log.debug("explanation, {}", timesheetApprovalRequest.explanation);
log.debug("startDate, {}", timesheetApprovalRequest.period.startDate);
log.debug("endDate, {}", timesheetApprovalRequest.period.endDate);

if (timesheetApprovalRequest.action == "SEND_TO_APPROVAL") {
  long[] dailyRequiredWorkInSeconds = worklogHelper.getDailyRequiredWorkInSeconds(timesheetApprovalRequest.userKey, timesheetApprovalRequest.period);
  log.debug("dailyRequiredWorkInSeconds:{}", dailyRequiredWorkInSeconds);
  long[] dailyActualWorkInSeconds = worklogHelper.getDailyActualWorkInSeconds(timesheetApprovalRequest.userKey, timesheetApprovalRequest.period);
  log.debug("dailyActualWorkInSeconds:{}", dailyActualWorkInSeconds);
  long requiredTotal = dailyRequiredWorkInSeconds.sum();
  log.debug("requiredTotal(seconds):{}", requiredTotal);
  long actualTotal = dailyActualWorkInSeconds.sum();
  log.debug("actualTotal(seconds):{}", actualTotal);
  if (actualTotal < requiredTotal) {
    return String.format("You can't submit timesheet. You have only provided %.2f of %.2f", actualTotal/3600, requiredTotal/3600);

  • No labels