Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to update the "Priority" field based another single choice custom field Value in jira.

Lakshmi CH
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.
February 12, 2020

Hi Team,

  I did not find the solution in our community and tried with behaviors also. We have field "Escalation?". If we change the "Escalation?" to Yes, the priority should change to Critical (after ticket creation).  I tried below code behaviors, but still not updating when we changed Escalation is yes. Could you please help me on this.

-------------------------------------------------------------

def escalationfield = getFieldByName("Escalation?")
def prio = getFieldByName("Priority")

if (escalationfield.getValue() == "Yes")
{
prio.setFormValue("Critical")
}

------------------------------------------------------------

 

2 answers

1 accepted

0 votes
Answer accepted
Leo
Community Champion
February 13, 2020

Hi @Lakshmi CH,

Below is the script for behaviour, I tested in project too

Note: you should use "Escalation"  field as source field & mapped to it

if (getFieldById(getFieldChanged()).getValue() == "Yes") {
getFieldById("priority").setFormValue("Critical")
}

And below script used for the same but in Script Listener

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.Issue

def issue = event.issue as Issue
def constantsManager = ComponentAccessor.getConstantsManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = new IssueInputParametersImpl()

def cfField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Custom Field Name")
def value = issue.getCustomFieldValue(cfField)
if(value == "Value 1"){
issueInputParameters.setPriorityId(constantsManager.getPriorityObjects().findByName("P1").id)
}else if(value == "Value 2"){
issueInputParameters.setPriorityId(constantsManager.getPriorityObjects().findByName("P2").id)
}else{
issueInputParameters.setPriorityId(constantsManager.getPriorityObjects().findByName("P3").id)
}

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

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

 

Hope it gives you  some idea

 

BR,
Leo

Lakshmi CH
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.
February 13, 2020

Perfect. This is working as expected. Thank you @Leo 

 

if (getFieldById(getFieldChanged()).getValue() == "Yes") {
getFieldById("priority").setFormValue("Critical")
}
balaji April 8, 2020

Hi @Leo Leo,

We have same scenario but diff custom field

If user select the value "minor" from impact custom field and "likely" from the probability custom field automatically priority must set to "medium"

 

Will this possible to achieve in behavior

Waiting for the your reply

 

Thanks!

Leo
Community Champion
April 8, 2020

Hi @balaji,

I would say YES. that is possible

As I mentioned above you'll have to map/write this behaviour with your custom field(Impact) and then the same script in server side script

if (getFieldById(getFieldChanged()).getValue() == "Minor") {
getFieldById("priority").setFormValue("Medium")
}

 

BR,

Leo

balaji April 8, 2020

hi @Leo 

Thanks for your reply,

As i mentioned above there are two fields called impact and probablity

based on the value priority system fields should change ,

 

Is that possible ?

Leo
Community Champion
April 9, 2020

@balaji 

you can map behaviour with single field which will be executed when the associated field changed/updated

Of course you can validate 2 field values in priority, but the drawback is below

1. If you map with 1st field, the script will be executed only when 1st field changed. if you change your 2nd field after 1st one. the validation will fail and priority will not be applied

The same goes for if you map with 2nd one.

If you really want to go with behaviour, you'll have write 2, and map each one with each field but with same script(I won't suggest that personally)

In this situation you can consider custom listener. where you can map with your project with issue created & updated event. here you can validate both fields values and update priority

you can refer my listener script above 

 

BR,

Leo

Drishti Maharaj
Contributor
January 26, 2022

Hi @Leo , I know this is a bit old but I came across this and it might help me. But I was wondering would this work if the custom field is a single choice list?

Would you need to add the name of the field and the choice or would it just be the choice alone?


if (getFieldById(getFieldChanged()).getValue() == "Cyber Incident Categorisation - Account Compromise") {
getFieldById("priority").setFormValue("P4")
}

I tried both ways but it did not seem to update accordingly.

Any help would be appreciated.

Thanks!

0 votes
Fallon Rohllf
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 17, 2021

When trying to set priority value on create screen a warning pops up:

These fields have default values for this project and issue type combination. We have preserved the existing values in case you need them.

Priority: 1

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events