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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published Monday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

476 views 7 8
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