Change Priority via Script Runner Listener not working on transition screens

Peter Steen Kristiansen September 22, 2017

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

3 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Kris Voog March 20, 2022

I've had the same problem trying to update issue priority via a listener based on custom field values entered during transitioning issue. The symptoms are as follows:


* Changing the custom field values on edit issue or view issue screen does update priority correctly.
* Changing the custom field values on a transition issue screen does produce an issue history log for priority change but does not actually change the priority value.


Using the IssueIndexingService does not help. Also, switching between different issue events do not matter as the listener is triggered correctly.


What I found is that using IssueManager updateIssue method does the trick, the problem only occurs while trying to update the issue via Atlassian's advised way to update an issue - using IssueService and all the validations.

0 votes
Frank Jaspers January 24, 2018

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

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 26, 2017

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.

Peter Steen Kristiansen September 27, 2017

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

TAGS
AUG Leaders

Atlassian Community Events