• Community
  • Products
  • Jira
  • Questions
  • Have two custom fields in create screen - Impact and Severity with values low, medium and high in select lists. When any user chooses the following values, priority custom field needs to be set automatically

Have two custom fields in create screen - Impact and Severity with values low, medium and high in select lists. When any user chooses the following values, priority custom field needs to be set automatically

case 1

impact = low severity = low then priority= low

case 2

impact = low and severity is medium then priority = low

case 3

impact = low and severity is high then priority = medium

case 4

impact = medium severity = low then priority= medium

case 5

impact = medium and severity = medium then priority = medium

case 6

impact = medium and severity = high then priority = high

case 7

impact = high severity = low then priority=high

case 8

impact =high and severity is medium then priority = high

case 9

impact = high and severity is high then priority = critical

8 answers

You can do this using the behaviours plugin...scripting is up to you though:

https://marketplace.atlassian.com/plugins/com.onresolve.jira.plugin.Behaviours

Please guide me to write script

hi how i can use that plugin can i have any scripts in place

1 vote
Renjith Pillai Community Champion Feb 04, 2013

If the relation between impact and severity with priority is fixed, why do you want to show the priority field itself in the screen? Accept the two values from the user for impact and severity and automatically set the value of priority in the post function using script runner plugin.

https://jamieechlin.atlassian.net/wiki/display/GRV/Script+Runner

Hi Dinesh,

Please modify this script accordingly.

Below script will work for if you want to autocopy data from one field to another. Design and modified script accordiangly and put in Description section of the field.

<script>
AJS.$(document).ready(function(){
AJS.$("input[name=customfield_xxxxx]").blur(function () {
var prjname= document.getElementsByName("customfield_xxxxxx")[0];
var summary= document.getElementsByName("summary")[0];
summary.value = prjname.value;

});

});
</script>

Good Luck!!

hi atul,

it is not used.

If you intend to calculate the priority of a risk, maybe you should take a look in the following plugin: https://marketplace.atlassian.com/plugins/com.ja.jira.plugin.report.riskmanagement

Hi all,

Sorry my short answer... bellow, a snippet code in Groovy (script "runner" post-function in "create" transition) used in one of our customers:

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

import webwork.dispatcher.ActionResult;
import com.atlassian.core.ofbiz.CoreFactory;
import com.atlassian.core.util.map.EasyMap;
import com.atlassian.jira.action.ActionNames
import org.ofbiz.core.entity.GenericValue;

import com.atlassian.core.ofbiz.CoreFactory
import com.atlassian.core.util.map.EasyMap
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.opensymphony.workflow.InvalidInputException
import org.apache.log4j.Category

def log = null

try{
  log = Category.getInstance("log.foobarwar.groovy");
  log.debug("INICIANDO SCRIPT setPriopridade.groovy")
}catch(Throwable e){
  System.out.println("ERRO ao obter a instancia do log4j")
  e.printStackTrace();
  return
}

ProjectManager projectManager = componentManager.getProjectManager()
//IssueManager issueManager = componentManager.getIssueManager()
//issueManager.getIssueObject( "UNILTM-36" )

MutableIssue mIssue = issue //Mutable issue

if( mIssue == null ){
  System.out.println("Não foi possivel obter a instancia da tarefa")
  return
}

// Matriz no formato [[[Urgencia,Impacto],Prioridade],...]
// Critica=2, Alta=3, Média=4 e Baixa=5
def matrizDePrioridade = [[["Alta","Alto"],"2"],[["Alta","Médio"],"3"],[["Alta","Baixo"],"4"],[["Média","Alto"],"3"],[["Média","Médio"],"4"],[["Média","Baixo"],"5"],[["Baixa","Alto"],"4"],[["Baixa","Médio"],"5"],[["Baixa","Baixo"],"5"],[["High","High"],"2"],[["High","Medium"],"3"],[["High","Low"],"4"],[["Medium","High"],"3"],[["Medium","Medium"],"4"],[["Medium","Low"],"5"],[["Low","High"],"4"],[["Low","Medium"],"5"],[["Low","Low"],"5"]]

def campoUrgencia   = "customfield_10160"
def campoImpacto    = "customfield_10161"

//Pega o valor do custom field Urgencia
String fieldValueUrgencia =  (String)mIssue.getCustomFieldValue( ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObject( campoUrgencia ) )?: "";

// Pega o valor do custom field Impacto
String fieldValueImpacto = (String)mIssue.getCustomFieldValue( ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObject( campoImpacto ) )?: "";

//log.warn("Urgencia =" +  fieldValueUrgencia  + " e Impacto = " +  fieldValueImpacto)

//Obtem a prioridade da atual tarefa conforme urgencia e impacto
def prioridade = ""
for (prioridades in matrizDePrioridade) {
	urgenciaImpacto = prioridades[0]
//	log.warn(urgenciaImpacto)
	if (urgenciaImpacto[0].contains(fieldValueUrgencia) &amp;&amp; urgenciaImpacto[1].contains(fieldValueImpacto)) {
		prioridade = prioridades[1]
		break
	}
}

//Valida se o usuario corrente esta somente em um grupo
if (prioridade.equals("") ) {
	log.warn("Problemas no calculo do campo Prioridade, Administrador do Sistema favor verificar a execução desta regra.")
	return
} 

// Seta o valor da prioridade calculado
mIssue.setPriorityId( prioridade )

//Persiste a tarefa com as alterações
mIssue.store()

//log.warn("Campo Prioridade setado com o valor " + prioridade + " com sucesso para issue " + mIssue.getKey())

where can i use this script and how can i modify this to my requirement

0 vote
Mizan Community Champion Feb 05, 2013

If you are new to behavoiurs plugin things will become more simpler if you go through the documentation of the plugin first , there are many examples provided in the documentation .

Below is an untested script , you will have to modify it accordingly

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField

FormField priority = getFieldById("priority")

FormField impact = getFieldById("impact") // Your customfield
Object impactValue = impact.getFormValue()


FormField severity = getFieldById("severity") // your customfield
Object severityValue = severity.getFormValue()

//pseudo logic .. syntax not tested ... not exaclty as per your requirement
if(impactValue==severityValue)
{
      priority.setFormValue(impactValue)
}

hi can i use this script for online editing

Mizan Community Champion Feb 05, 2013

No , if the fields are editable via inline edits then the script will not work . I guess this is handled by the plugin , if not you will need to turn off inline editing from General Configurations page.

hi mizan actuall y i cant understand some finctionality in the scripts will u transfer this script in to english please.

Please, too long tittle, edit it !

Hi Please correct my script it is not working

import com.onresolve.jira.groovy.user.FieldBehaviours

import com.onresolve.jira.groovy.user.FormField

FormField priority = getFieldById("priority")

FormField impact = getFieldById("impact") // Your customfield

Object impactValue = impact.getFormValue()

FormField severity = getFieldById("severity") // your customfield

Object severityValue = severity.getFormValue()

if((impactValue== "Low") && (severityValue == "Low"))

{

priority.setFormValue(Low)

}

if((impactValue== "Low") && (severityValue == "Medium"))

{

priority.setFormValue(Low)

}

if((impactValue== "Low") && (severityValue == "High"))

{

priority.setFormValue(Medium)

}

if((impactValue== "Medium") && (severityValue == "Low"))

{

priority.setFormValue(Medium)

}

if((impactValue== "Medium") && (severityValue == "Medium"))

{

priority.setFormValue(Medium)

}

if((impactValue== "Medium") && (severityValue == "High"))

{

priority.setFormValue(High)

}

if((impactValue== "High") && (severityValue == "Low"))

{

priority.setFormValue(High)

}

if((impactValue== "High") && (severityValue == "Medium"))

{

priority.setFormValue(High)

}

if((impactValue== "High") && (severityValue == "High"))

{

priority.setFormValue(Critical)

}

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,314 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot