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

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

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

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 Leader Feb 13, 2020

Hi @Lakshmi S,

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

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

 

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

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 Leader Apr 08, 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

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 Leader Apr 09, 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

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
Community showcase
Published in Confluence

🏑 Atlympic Event: Confluence

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

122 views 4 6
Read article

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