Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,085
Community Members
 
Community Events
176
Community Groups

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

3 answers

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.

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

Atlassian Community Events