Code for JIRA added functionality

I have in JIRA 3 custom fields: Priority (with 5 choices), change risk (with 3 choices) . If priorty equal "low" and change risk equals "Medium"  then the 3rd field will autofil with "normal" or one three choices.

I need some code to put in a script field (see image below), to make the above happen.

 

 

Is there a good plugin I can use, or........

I need some simple coding done and willing to pay someone to do this. Would you know anyone who can,

 or a site I can go to and advertise a need for this?

 

Change Category.png

 

1 answer

0 vote
Vasiliy Zverev Community Champion Jan 25, 2016

Try this code for scripted field, just change names for custom fields:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("ZV2-1")
if(issue == null)
    return "no such issue"

CustomField priority = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Сложность");
if(prioryty == null)
    return "no such field"

CustomField changeRisk = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Сложность");
if(prioryty == null)
    return "no such field"

if( ((Option) issue.getCustomFieldValue(prioryty)).getValue().equals("low")
    && ((Option) issue.getCustomFieldValue(changeRisk)).getValue().equals("normal")){
    return "normal"
}

Vasiliy, we are making progress!!  Thank you so much for this. I am working with another novice coder, we have a question: since "priority" is a standard field, and not a custom field is the code correct calling priority a CustomField?

CustomField priority = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Сложность");
if(prioryty == null)
    return "no such field"
Thanks!
John
Vasiliy Zverev Community Champion Jan 26, 2016

If you need to get standart field you should use methods of issue object to get it. 

In this case use: issue.getPriorityObject()

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

301 views 3 11
Read article

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