Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy Script

JIRA Team Mailbox March 14, 2016

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

0 votes
Aleks Yenin (Polontech)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2016

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.
kanchana wijerathna
Contributor
March 14, 2016

thanks problem resolved

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, social impact bingo, may it forward, atlassian foundation, community engagement, atlassian community events, atlassian learning, social impact challenge, volunteering, community kudos, atlassian social impact, atlassian community

Come one, come all!

Hey everyone! Are you ready to make a difference? Join the Atlassian Social Impact Bingo event! ❌⭕

Play Bingo! 🙋🏻‍♂️
AUG Leaders

Atlassian Community Events