Hi guys,
I need to associate an action while flagging a ticket. I want the status of the ticket to change to a different transition state automatically whenever I add a flag to the ticket. I don't want to use any plugins. Is this doable on Jira?
Thanks!!
I have a scripted solution for this, however it requires the ScriptRunner plugin.
Thanks Craig! Do you have any helper docs for the solution?
I have my comments Here's the script:It is setup as a Listener and updates a custom field when the flag is added.A second Listener is setup to clear the custom field when the flag is removed.
I know that's not exactly what you want but it should get you going.
I've included the groovy scripts for the Listeners below.I hope this helps.//Flag Added
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.event.type.EventDispatchOptionimport java.text.SimpleDateFormatimport java.util.Date.*import java.text.SimpleDateFormatimport java.sql.Timestampimport java.text.DateFormatimport java.util.Date
def today = new Date().format('MMM-dd-yyyy');
// Swapping the comment out to a string and then// doing a contains worked much better
// Field to Updatefinal customFieldName = 'Blocker Description'
def customFieldManager = ComponentAccessor.customFieldManagerdef loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser.namedef issue = event.issuedef commentManager = ComponentAccessor.commentManagerdef comment = commentManager.getLastComment(issue)def comment2 = comment.body.toString()if (comment2.contains("(flag) Flag added")) {// the new value of the fieldfinal newValue = "Flag Added By " + loggedInUser + " on " + today + comment2.minus("(flag) Flag added")// Make sure the field is theredef customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)assert customField : "Could not find custom field with name $customFieldName"customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), newValue), new DefaultIssueChangeHolder())}**********************************************//Flag Removed
def today = new Date().format('MMM-dd-yyyy'); //for mid-month report run// Swapping the comment out to a string and then// doing a contains worked much better
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser.namedef customFieldManager = ComponentAccessor.customFieldManagerdef issue = event.issuedef commentManager = ComponentAccessor.commentManagerdef comment = commentManager.getLastComment(issue)def comment2 = comment.body.toString()def customFieldSet = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)def customFieldValue = issue.getCustomFieldValue(customFieldSet).toString()if (comment2.contains("(flagoff) Flag removed")) {final newValue = ""// Make sure the field is theredef customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)assert customField : "Could not find custom field with name $customFieldName"customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), newValue), new DefaultIssueChangeHolder())}
Thanks a lot!
It looks like you're new here. Sign in or register to get started.