Example scripts
To homepage
Jira

Create a Tempo Plan when an Issue is Assigned to a User
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira (8.0 - 8.19)

ScriptRunner For Jira (7.10.0)
Language |
groovy
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.TrustedRequestFactory
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import groovy.json.JsonOutput
import groovyx.net.http.URIBuilder
import java.time.LocalDate
import java.time.format.DateTimeFormatter
@WithPlugin('com.tempoplugin.tempo-plan-core')
@PluginModule
ApplicationProperties applicationProperties
@PluginModule
TrustedRequestFactory trustedRequestFactory
// Default start time
final startTime = '09:00'
// Weekends and holidays are not included by default. If a plan needs to be created on weekends and holidays, set this to "true"
final includeNonWorkingDays = false
final today = LocalDate.now()
def issue = event.issue
def endDate = issue.dueDate?.toLocalDateTime()?.toLocalDate()
// Do nothing if the issue has been unassigned
if (!issue.assignee) {
return
}
if (!(issue.estimate && endDate)) {
log.error('Issue requires both an estimate and a due date. Plan not created')
return
}
def url = applicationProperties.getBaseUrl(UrlMode.CANONICAL) + '/rest/tempo-planning/1/plan'
def request = trustedRequestFactory.createTrustedRequest(Request.MethodType.POST, url)
def host = new URIBuilder(url).host
request.addTrustedTokenAuthentication(host)
request.setRequestBody(JsonOutput.toJson([
assigneeKey : 'JIRAUSER10000',
assigneeType : 'USER',
day : DateTimeFormatter.ISO_LOCAL_DATE.format(today),
end : DateTimeFormatter.ISO_LOCAL_DATE.format(endDate),
includeNonWorkingDays: includeNonWorkingDays,
planItemId : issue.id,
planItemType : 'ISSUE',
secondsPerDay : issue.estimate,
start : DateTimeFormatter.ISO_LOCAL_DATE.format(today),
startTime : startTime
]), 'application/json')
request.execute()
Having an issue with this script?
Report it here