I have a groovy script which updates a Group Custom Field value, but when i run the options will get null,

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.ComponentManager;

import com.atlassian.jira.issue.fields.CustomField;

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.issue.customfields.option.Option

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import com.atlassian.jira.issue.ModifiedValue

import com.atlassian.jira.issue.customfields.option.Options

 

import org.apache.log4j.Category

import com.atlassian.jira.issue.customfields.manager.OptionsManager

 

def Category log = Category.getInstance("com.onresolve.jira.groovy")

log.setLevel(org.apache.log4j.Level.DEBUG)

 

MutableIssue issue = issue

 

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

CustomField essTeam = customFieldManager.getCustomFieldObjectByName("ESS Team")

OptionsManager optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)

 

log.debug "Starting"

 

if(ComponentManager.getInstance().getUserUtil().getGroupNamesForUser(issue.reporterId).contains("ESS Team")){

        OptionsManager optManager = ComponentAccessor.getOptionsManager();

        Options options = optManager.getOptions(essTeam.getRelevantConfig(issue));   

        Option newOption = options.getOptionById(5);

        ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(essTeam ), newOption );

        essTeam.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());

        log.debug "Team is " + options

} else {

        OptionsManager optManager = ComponentAccessor.getOptionsManager();

        Options options = optManager.getOptions(essTeam.getRelevantConfig(issue));

        Option newOption = options.getOptionById(5);

        ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(essTeam ), newOption );

        essTeam.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());

        log.debug "Team is " + options

}

 

What is the issue, issue is not updating as well

1 answer

Is your code a postfunction or just running from a scriprunner?

Retrieving issue this way

MutableIssue issue = issue

is only acceptable while writing a postfunction. 

While running script from a scriptrunner you should define iisue by your own, e.g.

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("AP-10");
//Replace key "AP-10" with issue key you need.

thanks problem resolved

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...

81 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