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

This widget could not be displayed.

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
Community showcase
Asked yesterday in Data Center

Hi! I'm Cameron Deatsch, enterprise enthusiast and Head of Server at Atlassian. AMA!

Hey team! I'm Cameron Deatsch, Head of Server at Atlassian. At our European Summit just a few weeks ago, I spoke about the latest regarding our Server and Data center products and o...

19,272 views 4 4
View question

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