Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Transition Via Scriptrunner Doesn't Start SLAs Edited

I have a listener that catches a comment then checks if the comment was made by the reporter.  If so, and if the issue is currently in "Pending Customer" status, I'll transition it either to "Tier 2" or "In Progress", depending on the value of another custom field.  My Time to Resolution SLA is paused when in "Pending Customer", and should start back up after transitioning to "Tier 2" or "In Progress".  I recently added the code to fire an event, thinking that might knock the SLA loose.  

Any ideas on how to get the SLA to un pause?

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import com.onresolve.jira.groovy.user.FieldBehaviours;
import com.onresolve.jira.groovy.user.FormField;
import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.jira.event.issue.IssueEventBundle;
import com.atlassian.jira.event.issue.IssueEventManager;
import com.atlassian.jira.event.issue.IssueEventBundleFactory;
import com.atlassian.jira.event.issue.IssueEvent;

def status = issue.getStatusObject().getName()
def commentManager = ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(issue)

//log.warn("defined userManager")
//log.warn(issue.getId())
//log.warn(issue.issueTypeObject.name)

if (["Pending Customer","Closed"].contains(status) && ["Incident","Service Request"].contains(issue.issueTypeObject.name)) {//(issue.issueTypeObject.name == "Incident" || issue.issueTypeObject.name == "Service Request")) {
//log.warn("Inside Status IF")

if (comments) {
//log.warn("yes there were comments found")
def author=comments.last().authorApplicationUser.getName()
//log.warn("author is: " + author)
def reporter=issue.getReporter().getName()
//log.warn("reporter is: " + reporter)

if (author==reporter) {
//log.warn("author=reporter")

// if this is closed, then we send an email to the customer and return true
if (["Closed"].contains(status)) {
log.warn("status is Closed and comment was made by reporter, send bounceback email")
//FormField supervisor = getFieldById(fieldChanged)
ComponentManager componentManager = ComponentManager.getInstance()
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();

if (mailServer) {
//log.warn("mailServer constructed successfully")
def reporterFullName = issue.getReporter().getDisplayName()
def emailAddress = comments.last().authorApplicationUser.getEmailAddress().toString()
//log.warn(emailAddress)
Email email = new Email(emailAddress)// Set the TO address, optionally CC and BCC
//log.warn(email)
email.setSubject("${issue.getKey()} ${issue.summary}") // todo: check the subject value
def project = issue.projectObject.name
String contentEnglish = "${reporterFullName},\r\n\r\nThank you for contacting";
String contentEnglishFrench = "${reporterFullName},\r\n\r\nThank you for contacting";

if (["Information Technology - Canada","People Business Services (PBS) - Canada","Business Services Center Canada"].contains(project)) {
email.setBody(contentEnglishFrench)
}
else {
email.setBody(contentEnglish)
}
//log.warn(email)
mailServer.send(email)

return true
}
else {
log.error("No SMTP mail server defined")
}
}
// Let's transition depending on value of reporting tier
def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjectByName("Reporting Tier")
//log.warn(issue.getCustomFieldValue(customField))

if (issue.getCustomFieldValue(customField).toString().trim()=="Tier 2") {
// Transition to tier 2
log.warn("comment made by reporter, status is pending customer, let's transition to tier 2")

def currentUser = ComponentAccessor.getUserManager().getUserByName("automation-system-user") //ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject(event.issue.key)
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 161 // this is the "resume tier 2" transition in ITCAN
def transitionValidationResult
def transitionResult
//log.warn("The issue type is: " + issue.getIssueType().name)
transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId, new IssueInputParametersImpl())

if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)

if (transitionResult.isValid()) {
log.warn("Transitioned issue $issue through action $actionId")

// fire issue updated event
Long EVENT_ID = new Long("13") // 2=issue updated event

IssueEventManager issueEventM = ComponentAccessor.getIssueEventManager()
IssueEventBundleFactory issueEventFactory = (IssueEventBundleFactory) ComponentAccessor.getComponent(IssueEventBundleFactory.class)

IssueEventBundle eventBundle = issueEventFactory.wrapInBundle(new IssueEvent (issue, null, currentUser, EVENT_ID, true))
issueEventM.dispatchEvent(eventBundle)
log.warn("fired issue updated event")
}
else {
log.warn("Transition result is not valid") }
}
else {
log.warn("The transitionValidation is not valid")
}
}
else {
// Transition to in progress
log.warn("comment made by reporter, status is pending customer, let's transition to in progress")

def currentUser = ComponentAccessor.getUserManager().getUserByName("automation-system-user") //ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject(event.issue.key)
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 151 // this is the "resume in progress" transition in ITCAN
def transitionValidationResult
def transitionResult
//log.warn("The issue type is: " + issue.getIssueType().name)
//log.warn(currentUser)
transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId, new IssueInputParametersImpl())

if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid()) {
log.warn("Transitioned issue $issue through action $actionId")

// fire issue updated event
Long EVENT_ID = new Long("13") // 2=issue updated event

IssueEventManager issueEventM = ComponentAccessor.getIssueEventManager()
IssueEventBundleFactory issueEventFactory = (IssueEventBundleFactory) ComponentAccessor.getComponent(IssueEventBundleFactory.class)

IssueEventBundle eventBundle = issueEventFactory.wrapInBundle(new IssueEvent (issue, null, currentUser, EVENT_ID, true))
issueEventM.dispatchEvent(eventBundle)
log.warn("fired issue updated event")
}
else {
log.warn("Transition result is not valid")
}
}
else {
log.warn("The transitionValidation is not valid")
}
}
}
else {
//log.warn("author!=reporter")
//do nothing
}
}
else {
//log.warn("No Comment Made")
//do nothing
}

 

1 answer

Hi, did you find the solution? We have the same logic (customer -> tier 1/2) and the same issue.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Statuspage

New feature: Slack notifications for Statuspage

We're excited to announce the release of a long-requested feature on Statuspage. Now visitors to your status page can subscribe to get notified in Slack when you report an incident or maintenance. Th...

81 views 0 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you