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 Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

277 views 0 12
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot