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')
}
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')
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually, it works as expected although there is a warning.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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'])
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.