7 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2016

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

ayman qaddoura November 12, 2016

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

 

ayman qaddoura November 14, 2016

Dear Adam,

Do you have any update on the below please

Regards

ayman qaddoura November 16, 2016

Hi adam,

 

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

 

Regards 

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 20, 2016

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

ayman qaddoura November 23, 2016

 

@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

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 23, 2016

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

ayman qaddoura November 25, 2016

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)

   

ayman qaddoura November 28, 2016

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

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 28, 2016

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

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

to debug the problem.

ayman qaddoura November 28, 2016

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)

 

 

ayman qaddoura November 30, 2016

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

your continues support is highly appreciated 

 

thanks again 

ayman qaddoura December 5, 2016

@Adam Markham [Adaptavist] Any update please ? 

ayman qaddoura December 6, 2016

@Adam Markham [Adaptavist] Kind reminder 

ayman qaddoura December 12, 2016

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

i need your support 

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 12, 2016

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.

ayman qaddoura December 13, 2016

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

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2016

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.

1 vote
Дмитрий Тягунов December 28, 2016

Thanks. It is ultra good example!

1 vote
Jörg Griepentroch November 11, 2015

Hello,

your solution is working.

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

1 vote
Jeff Louwerse
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2015

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.

 

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2016

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.

0 votes
Jonas Pg Svensson November 6, 2018

@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 

0 votes
ayman qaddoura November 10, 2016

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
0 votes
ayman qaddoura November 10, 2016

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events