Page tree
Skip to end of metadata
Go to start of metadata

Requirements

Let's assume that a user has the following requirements.

Service window: Monday-Sunday, 08:00 - 22:00

Resolution time: End of next business day

If the ticket was created today, it must be resolved tomorrow by 22:00. Otherwise the SLA will be breached.

Solution

Add the following script as a post function to the Create transition in the issue's workflow. This post function is designed to set a date-time custom field named "Nextday" to next weekday at 10:00 PM.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import java.sql.Timestamp

//MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("issueKey"); //For Script console only

Calendar newDate = Calendar.getInstance();
newDate.setTime(issue.getCreated());
newDate.set(Calendar.HOUR_OF_DAY, 22);
newDate.set(Calendar.MINUTE, 00);
newDate.set(Calendar.SECOND, 0);
newDate.add(Calendar.DAY_OF_YEAR, 1);
issue.setCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Nextday"), 
		new Timestamp(newDate.getTimeInMillis()))
ComponentAccessor.getIssueManager().updateIssue(
        ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),
        issue,
        UpdateIssueRequest.builder().sendMail(false).eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).build())


Since this post function is in the Create transition, "Stores updates to an issue (no change history is created)." post function after the above custom script post function should be added too.

After these steps, the SLA configuration is pretty straightforward.

SLA Start: Date Field: Jira Field: Created
SLA End: Status: Done // Customize this as you wish
SLA Goal: Negotiation Date: Nextday
JQL Condition: Project=abc // Customize this as you wish

You may want to limit this SLA to the projects or issue types where the Nextday custom field is set, otherwise, this SLA will show up as INVALID in the view issue page.


  • No labels