Change Priority via Script Runner Listener not working on transition screens Edited

Hi,

We have a script runner listener which changes the Priority based on two custom fields; Impact and Urgency.

When Impact and Urgency are changed either via quick edit or edit mode for the issue it works, and Priority is updated. However when changing Impact or Urgency on a transition screen the Priority is not changed. Even when the Priority field is on the screen (in case that would matter).

The script:

package pfa.listener.ImpactUrgency

import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.security.JiraAuthenticationContext

class TaskVersionListener extends AbstractIssueEventListener {
Category log = Category.getInstance(TaskVersionListener.class)

@Override
void workflowEvent(IssueEvent event) {
MutableIssue issue = (MutableIssue) event.issue
def impactMap=["Low":3, "Medium":2, "High":1];
def urgencyMap=["Low":3, "Medium":2, "High":1];

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cf_impact = customFieldManager.getCustomFieldObject("customfield_10577")
CustomField cf_urgency = customFieldManager.getCustomFieldObject("customfield_10578")

String impact = new String(issue.getCustomFieldValue(cf_impact).toString().getBytes(), "UTF-8")
String urgency = new String(issue.getCustomFieldValue(cf_urgency).toString().getBytes(), "UTF-8")

def calculatedPriority=0
if (impact != 'null' && urgency != 'null'){
calculatedPriority = impactMap[impact] + urgencyMap[urgency] -1
}else{
calculatedPriority = 4
}

def priority = calculatedPriority.toString()
def constantsManager = ComponentAccessor.getConstantsManager()
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = new IssueInputParametersImpl()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

issueInputParameters.setPriorityId(priority)
issueInputParameters.setSkipScreenCheck(true)

def updateValidationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)

if (updateValidationResult.isValid()) {
issueService.update(user, updateValidationResult)
} else {
log.warn updateValidationResult.errorCollection.errors
}
}
}

We are running JIRA 7.3.4 and Script Runner 4.3.19.

The listener is set up to the following Events: Issue Created and Issue Updated. I tried adding Generic Event (as that is what is fired by the workflow transition) but with no luck.

<edit>

Further investigation, has shown that the Listener IS fired. I can log output and I can even see that I can read values out of the custom fields. The only thing missing is that the Priority field is not updated.

</edit>

Any suggestions?

br

Peter

2 answers

0 vote

Since we know that the issue created and Issue updated events are working here, I would suggest trying to edit the workflow itself.  You can specifically change the post function that is associated with this transition.

If you edit that workflow, go to post functions, then edit the Fire a Generic Event, you can change this to a value such as Issue Updated.

work1.png

 

work2.png

You can then publish this workflow, at which point the use of that transition should then fire off the issue updated event, and in turn trigger your script.

Since the execution of this transition is expected to change the status of the issue, I can't really think of any side-effects for this kind of workflow change.

Hi,

Thank you for the suggestion - I tried to set the workflow transition to invoke an Issue Updated event instead, but get the same result. Priority is not updated.

Further investigation, has shown that the Listener IS fired. I can log output and I can even see that I can read values out of the custom fields. The only thing missing is that the Priority field is not updated.

(I'll update my original question with this information as well).

br

Peter

Are there any other ideas to solve the problem? Because I'm in the same spot.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

70 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you