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,363,464
Community Members
 
Community Events
168
Community Groups

How I Can update System Priority Fields from to two another custom fields

Hi Community,

I want to set Priority field from two another custom field directly on creation screen.

To set the priority, I want to use a combinaison of repeatability value and severity value.

I try to had Post-function with jMWE plugin with no result.

with this groovy expression in Value box

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def repeat=customFieldManager.getCustomFieldObjects(issue)?.find { it.id == "customfield_17394"}
def severity=customFieldManager.getCustomFieldObjects(issue)?.find { it.id == "customfield_17393"}
def repeatVal=issue.getCustomFieldValue(repeat)
def severityVal=issue.getCustomFieldValue(severity)
def highest="10303"
def high="10300"
def low="10302"
def lowest="10301"

if (repeatVal == "Non identifié" && severityVal == "Bloquant" ){
issue.setPriorityId(highest)
}

if (repeatVal == "Non identifié" && severityVal == "Critique" ){
issue.setPriorityId(highest)
}

if (repeatVal == "Non identifié" && severityVal == "Majeur" ){
issue.setPriorityId(highest)
}

if (repeatVal == "Reproductible" && severityVal == "Bloquant" ){
issue.setPriorityId(highest)
}

if (repeatVal == "Intermittent" && severityVal == "Bloquant" ){
issue.setPriorityId(highest)
}

if (repeatVal == "Non identifié" && severityVal == "Mineur" ){
issue.setPriorityId(high)
}

if (repeatVal == "Reproductible" && severityVal == "Majeur" ){
issue.setPriorityId(high)
}

if (repeatVal == "Intermittent" && severityVal == "Critique" ){
issue.setPriorityId(high)
}

if (repeatVal == "Unique" && severityVal == "Bloquant" ){
issue.setPriorityId(high)
}

if (repeatVal == "Reproductible" && severityVal == "Mineur" ){
issue.setPriorityId(low)
}

if (repeatVal == "Intermittent" && severityVal == "Majeur" ){
issue.setPriorityId(low)
}

if (repeatVal == "Unique" && severityVal == "Critique" ){
issue.setPriorityId(low)
}

if (repeatVal == "Intermittent" && severityVal == "Critique" ){
issue.setPriorityId(lowest)
}

if (repeatVal == "Unique" && severityVal == "Majeur" ){
issue.setPriorityId(lowest)
}

Anyone can help me ?

1 answer

0 votes

Hi @Christophe ARON ,

since you're using JMWE, there's actually a must easier way to achieve this. All you need is a Set Field Value post-function with the following settings:

- Field: Priority

- Value type: Groovy Expression

- Value: something along the lines of the following Groovy script:

def repeatVal = issue.getAsString("customfield_17394")
def severityVal = issue.getAsString("customfield_17393")


def highest="10303"
def high="10300"
def low="10302"
def lowest="10301"

switch(repeatVal) {
case "Non identifié":
switch(severityVal) {
case "Bloquant": return highest
case "Critique": return highest
 case "Majeur": return highest
  case "Mineur": return high
default: return low
}
case "Reproductible":
switch(severityVal) {
case "Bloquant": return highest
case "Critique": return highest
  case "Majeur": return high
   case "Mineur": return low
default: return low
}
//etc for the other values for repeatVal
}

This approach makes the code much more readable, and avoids forgetting some combinations (as you did in your code - e.g. Reproductible + Critique)

Hi David,

 

Thanks for your reply, when I reading again documentation I saw that I'm going wrong.

You're code is more clearly and easy.

Thanks, this approach work well!

That's solved my problem.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events