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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
import java.text.SimpleDateFormat
import java.util.Date.*
import java.text.SimpleDateFormat
import java.sql.Timestamp
import java.text.DateFormat
import 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 Update
final customFieldName = 'Blocker Description'
def customFieldManager = ComponentAccessor.customFieldManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser.name
def issue = event.issue
def commentManager = ComponentAccessor.commentManager
def comment = commentManager.getLastComment(issue)
def comment2 = comment.body.toString()
if (comment2.contains("(flag) Flag added")) {
// the new value of the field
final newValue = "Flag Added By " + loggedInUser + " on " + today + comment2.minus("(flag) Flag added")
// Make sure the field is there
def 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
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
import java.text.SimpleDateFormat
import java.util.Date.*
import java.text.SimpleDateFormat
import java.sql.Timestamp
import java.text.DateFormat
import java.util.Date
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
// Field to Update
final customFieldName = 'Blocker Description'
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser.name
def customFieldManager = ComponentAccessor.customFieldManager
def issue = event.issue
def commentManager = ComponentAccessor.commentManager
def 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 there
def 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())
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.