Change custom field depending on the value of another custom field

I need to make a transition (Open > Backlog) and change a custom field "time" depending on the value of the custom field "module".

Example that works with Script Runner:

 

def cfsat = customFieldManager.getCustomFieldObjects (issue) .find {it.name == 'Module'}
def module = issue.getCustomFieldValue (cfsat)
def time = ''
switch (module) {
	case 'Satelite - AUD': A: {
		time = 'timeaud'
		break
	}
	case 'Satelite - Conector': B: {
		time = 'timeconector'
		break
	}
	case 'Satelite - Consulta': C: {
		time = 'timeconsulta'
		break
	}
}

 

But Script Runner is now paid to work with Jira 7. So, I installed Automation JIRA plugin but it does not make the conditions: switch, if..else, etc.

Some help to make a transition (Open > Backlog) and change custom field (time) depending on the value of another custom field (modulo) ?

Thanks.

2 answers

Hi SITEC,

                  Currently I have only tested against Script Runner

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.*;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.ModifiedValue as ModifiedValue;
//Managers
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
IssueManager issueManager = ComponentAccessor.getIssueManager();
//UserManager userManager = ComponentAccessor.getUserManager();
IssueFactory issueFactory = ComponentAccessor.getIssueFactory();
//User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
//SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
//IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
//IssueLinkTypeManager issueLinkTypeManager = (IssueLinkTypeManager)ComponentAccessor.getComponentOfType(IssueLinkTypeManager.class)
MutableIssue mIssue = issueFactory.getIssue();
Issue issue = issueManager.getIssueObject("SRT-8");
def source = customFieldManager.getCustomFieldObject("customfield_14700");
//return tgtField;
sourceValue = issue.getCustomFieldValue(source)
//return sourceValue;
if (sourceValue*.value.contains("Satelite"))
{
    def tgtField = customFieldManager.getCustomFieldObject("customfield_14701");
    def changeHolder = new DefaultIssueChangeHolder();
    tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), "some new value"),changeHolder);
    
}
  • Don't know other plugins which can do the same

 

Hi Chander Inguva,

I already have a solution with Script Runner (example above) in Jira 6.3.15. But it is no longer free.

I need a free solution for Jira 7. Any help?

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 Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

64 views 0 5
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