Forums

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

Update the Label field based on priority field

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.
September 28, 2021

Hi Team,

  We would like to implement the below scenarios.

If the ticket priority is critical - automatically add a Priority1 to Label field. If the ticket is any other priority add a Priority2 value to Label field.

I have tried the below behavior using script runner, but the Label field is not updating with the values based on priority

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.priority.Priority
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

if ((getFieldById(fieldChanged).value as Priority)?.name == 'Critical') {
getFieldById('Labels')
.setLabel('Priority1')

} else {
getFieldById('Labels')
.setLabel('Priority2')

}

1 answer

1 vote
Tansu Akdeniz
Community Champion
September 28, 2021

Hi @Lakshmi CH 

Please take a look at this sample which may guide you.

def priorityField = getFieldById(getFieldChanged())
def labelsField = getFieldById("labels")

String priorityVal = priorityField.getValue().getName()

if(priorityVal.equals("Critical")){
labelsField.setFormValue('Priority1')
} else {
labelsField.setFormValue('Priority2')
}
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.
September 29, 2021

Hi @Tansu Akdeniz 

 I am getting this error when i am trying this script. Can you please suggest ?

s1.PNGs2.PNG

Tansu Akdeniz
Community Champion
September 29, 2021

Actually, it works as expected although there is a warning.

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.
September 29, 2021

Hi @Tansu Akdeniz ,

 Yes, Its working. Thank you so much for your quick responses.  While creating the ticket the priority default value is Minor, as per the requirement if the priority value is Critical, the Label should be updated to Priority1, so the ticket is taking both the values when i am changing the Priority to Critical while creating the ticket. Please find the attached screenshot for your reference.

s1.PNG

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.
September 29, 2021

Hi @Tansu Akdeniz ,

 Can you please suggest on this.  I tried with below code also, but not working. This code is clearing the field value. When i am giving Label is Priority1 manually , and selecting other priority its clearing the value in the label field.

def priorityField = getFieldById(getFieldChanged())
def labelsField = getFieldById("labels")

String priorityVal = priorityField.getValue().getName()

if(priorityVal.equals("Critical")){
labelsField.setFieldOptions(["Priority1"])
labelsField.setFormValue(['Priority1'])
} else {
labelsField.setFieldOptions(["Priority2"])
labelsField.setFormValue(['Priority2'])
}

Suggest an answer

Log in or Sign up to answer