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

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

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

0 votes
Andy Heinzer Atlassian Team Sep 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.

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

Suggest an answer

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

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

533 views 1 10
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