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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

7 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

You can use this custom post-function script below which will set the priorities according to the matrix in the Atlassian Documentation.

You need to go to your workflow add post-function and then choose scripted post-function of which you need to select "Custom script post-function"

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.customfields.option.Option

// This is a two dimensional map to represent the matrix
// Keys along left is urgency and second dimension keys is the impact
def priorityMatrix = [
    Critical: [Extensive: "Critical", Significant: "Critical", Moderate: "High", Minor: "Medium"],
    High    : [Extensive: "Critical", Significant: "High", Moderate: "Medium", Minor: "Medium"],
    Medium  : [Extensive: "High", Significant: "Medium", Moderate: "Medium", Minor: "Low"],
    Low     : [Extensive: "Medium", Significant: "Medium", Moderate: "Low", Minor: "Low"],
]

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()

def issue = issue as Issue

def urgencyField = customFieldManager.getCustomFieldObjectByName("Urgency")

def impactField = customFieldManager.getCustomFieldObjectByName("Impact")

def urgency = issue.getCustomFieldValue(urgencyField) as Option
def impact = issue.getCustomFieldValue(impactField) as Option

def priorityName = priorityMatrix[urgency.value][impact.value]

def priority = constantsManager.getPriorityObjects().findByName(priorityName)


def issueInputParameters = new IssueInputParametersImpl()

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

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

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

You should add this as the last post-function on the create transition and assuming you have added the correct priorities and the two custom fields urgency and impact, this will work.

You can use:

mutableIssue.setPriorityId(priorityId);

but it depends on where you place the post-function, above we use the issue service which will do the update in the database and the reindexing.

Hope this helps.

Adam

Thank you Very much Adam it works fine with me when i create new issue 

but can you please guide me how can i do the same when i want to update an existing issue where should i put the post function in this case 

Appreciate your help

 

Dear Adam,

Do you have any update on the below please

Regards

Hi adam,

 

sorry for bothering you , did you find anything regarding my last question 

 

Regards 

You should place this as the last post-function on any other transition. It should work for both create and update.

 

@Adam Markham [Adaptavist] i added the post function as a last of create trasition and it works fine , but my problem is when i want to update the severity and urgency later , the priority is not changing because the status of the issue doesnt change (workflow transitions are not triggered here ) check the attached image which will show you what i mean by update the issue 

 

image2016-11-24 9:46:27.png

You should in addition to the post-function have a Scripted Listener "custom listener" for the "Issue Updated" event for that project. Admin -> Script Listeners ->  "custom listener".

Instead of this line in the script:

def issue = issue as Issue

you need to replace it with:

def issue = event.issue as Issue

That should set the priority when you update them two fields.

More about custom listeners here: https://scriptrunner.adaptavist.com/latest/jira/listeners.html#_custom_listeners

Thank you @Adam Markham [Adaptavist]

i created the listener but it didnt work with me i found the below error in the script 

 

Time (on server): Fri Nov 25 2016 14:34:04 GMT+0300 (Arab Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2016-11-25 11:34:04,474 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2016-11-25 11:34:04,476 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException
	at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
	at com.atlassian.jira.issue.Issue$getCustomFieldValue$10.call(Unknown Source)
	at Script49.run(Script49.groovy:27)

   

@Adam Markham [Adaptavist] do you have any update please ? 

It looks like one of the custom fields is null. Try adding:

log.warn(impactField)
log.warn(urgencyField)

to debug the problem.

Dear @Adam Markham [Adaptavist] 

i got the below errors 

 

Time (on server): Tue Nov 29 2016 12:29:18 GMT+0300 (Arab Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2016-11-29 09:29:18,402 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2016-11-29 09:29:18,403 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException
	at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
	at com.atlassian.jira.issue.Issue$getCustomFieldValue$10.call(Unknown Source)
	at Script60.run(Script60.groovy:27)

 

 

Time (on server): Tue Nov 29 2016 12:29:16 GMT+0300 (Arab Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2016-11-29 09:29:16,494 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2016-11-29 09:29:16,494 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException
	at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
	at com.atlassian.jira.issue.Issue$getCustomFieldValue$10.call(Unknown Source)
	at Script60.run(Script60.groovy:27)

 

 

Time (on server): Tue Nov 29 2016 12:29:18 GMT+0300 (Arab Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2016-11-29 09:29:18,402 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2016-11-29 09:29:18,403 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException
	at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
	at com.atlassian.jira.issue.Issue$getCustomFieldValue$10.call(Unknown Source)
	at Script60.run(Script60.groovy:27)

 

 

@Adam Markham [Adaptavist] please try to help me in this ASAP 

your continues support is highly appreciated 

 

thanks again 

@Adam Markham [Adaptavist] Any update please ? 

@Adam Markham [Adaptavist] Kind reminder 

@Adam Markham [Adaptavist] Please let me know if you will help me in this or not 

i need your support 

I can not reproduce the same problem you have with the listener. I think its due to you having different options for Impact and Urgency in your single select lists or different priorities. I have the same ones as in this table here along with all the priorities and it works: https://confluence.atlassian.com/servicedeskcloud/automating-the-calculation-of-priority-based-on-impact-and-urgency-values-on-issue-creation-827107708.html

Your listener should look like:
Screen Shot 2016-12-13 at 10.36.11.png

Your script for the listener should also look like:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.customfields.option.Option

// This is a two dimensional map to represent the matrix
// Keys along left is urgency and second dimension keys is the impact
def priorityMatrix = [
    Critical: [Extensive: "Critical", Significant: "Critical", Moderate: "High", Minor: "Medium"],
    High    : [Extensive: "Critical", Significant: "High", Moderate: "Medium", Minor: "Medium"],
    Medium  : [Extensive: "High", Significant: "Medium", Moderate: "Medium", Minor: "Low"],
    Low     : [Extensive: "Medium", Significant: "Medium", Moderate: "Low", Minor: "Low"],
]

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()

def issue = event.issue as Issue

def urgencyField = customFieldManager.getCustomFieldObjectByName("Urgency")

def impactField = customFieldManager.getCustomFieldObjectByName("Impact")

def urgency = issue.getCustomFieldValue(urgencyField) as Option
def impact = issue.getCustomFieldValue(impactField) as Option

def priorityName = priorityMatrix[urgency.value][impact.value]

def priority = constantsManager.getPriorityObjects().findByName(priorityName)


def issueInputParameters = new IssueInputParametersImpl()

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

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

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

Also check your fields are called "Urgency" and "Impact" and have the same values as in the table.

Dear @Adam Markham [Adaptavist] please check the attached all what you mentioned is correct 

 

image2016-12-13 14:31:55.pngimage2016-12-13 14:33:16.pngimage2016-12-13 14:32:31.png

The table in the link shows different values for Urgency and Severity to what you have, you need to change these to what I have below:

Urgency
ImpactCriticalHighMediumLow
ExtensiveCriticalCriticalHighMedium
SignificantCriticalHighMediumMedium
ModerateHighMediumMediumLow
MinorMediumMediumLowLow

For Impact I have "Extensive, Significant, Moderate, Minor"

For Urgency I have "Critical, High, Medium, Low"

If you want to use just Low, Medium and High you will have to update the "priorityMatrix" values.

I assume your problem is actually updating the priority field and is a post function or listener and not a Behaviour? .. if so please see my answer from a week ago.  

https://answers.atlassian.com/questions/32018886

You will need your own code/logic to get the value you want to update the priority to but this example shows how to update the priority.  If this part is your problem, please post what you have so far and I can help.

 

if you are doing this using Behaviours.. that that is another case all together.

 

Just as a side if this is on the create transition in particular, you should place the scripted post-function as your last one in the list.

Hello,

your solution is working.

Thank you very much, finally this problem is solved. :)

Thanks. It is ultra good example!

Hi 

 

i want to Automate the calculation of priority on my jira  software exactly like what described in the below link but the steps in the link is for jira service desk while i want it for jira and i cant find the automation can you please help me 

https://confluence.atlassian.com/servicedeskcloud/automating-the-calculation-of-priority-based-on-impact-and-urgency-values-on-issue-creation-827107708.html

 

my priorities table matrix below 

 

Urgency/Severity
High
Medium
Low
HighBlockerUrgentHigh
LowHighMediumLow
MediumUrgentHighMedium

Hi 

 

i want to Automate the calculation of priority on my jira  software exactly like what described in the below link but the steps in the link is for jira service desk while i want it for jira and i cant find the automation can you please help me 

https://confluence.atlassian.com/servicedeskcloud/automating-the-calculation-of-priority-based-on-impact-and-urgency-values-on-issue-creation-827107708.html

 

my priorities table matrix below 

 

Urgency/Severity
High
Medium
Low
HighBlockerUrgentHigh
LowHighMediumLow
MediumUrgentHighMedium

@adammarkham The priorityMatrix doesn't really comply with the commandline 

def priorityName = priorityMatrix[urgency.value][impact.value]

Screen Shot 2018-11-06 at 16.54.42.png

 basically the priorityName is null 

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS

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