Script runner, how to update custom field that's a select list?

I can't seem to find any good documentation on Script Runner or any examples for doing this online. The one link I found that seemed promising doesn't work, and I can't find documentation to figure out what's wrong. Does anyone have any examples of updating a select list custom field in a post function on a transition? Also, is there a good resource for Script Runner out there? Script runner seems very powerful, but it's lacking heavily in documentation. I love jira-python and am really productive with it even though I don't know python just because the documentation is so good. It seems like you really could do anything with Script Runner if it had decent docs/examples.

 

Here's what I have...

/*
IF issue has the 'Assigned QA' field populated, set 'QA % Complete' value to 100 when issue is closed 
*/
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;

MutableIssue issue = issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def qaResourceCf = customFieldManager.getCustomFieldObjectByName("Assigned QA")
def qaResource = issue.getCustomFieldValue(qaResourceCf)
def CustomFieldManager cFM_QAPercent = ComponentManager.getInstance().getCustomFieldManager()
def CustomField qaPercent = cFM_QAPercent.getCustomFieldObjectByName("QA % Complete")

def Options options = WebAppsCf.getOptions(null, qaPercent.getRelevantConfig(issue), null);
def Option newOption = options.getOptionById(10840);

ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(qaPercent), newOption );
if (qaResource) {
    customField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());
}

 

 

Here are the errors I get:

Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 16: unable to resolve class Options
 @ line 16, column 13.
   def Options options = WebAppsCf.getOptions(null, qaPercent.getRelevantConfig(issue), null);
               ^
 @ line 17, column 12.
   def Option newOption = options.getOptionById(10840);
              ^
Script1.groovy: 19: unable to resolve class ModifiedValue
 @ line 19, column 15.
   ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(qaPercent), newOption );
                 ^
Script1.groovy: 19: unable to resolve class ModifiedValue
 @ line 19, column 22.
   ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(qaPercent), newOption );
                        ^
Script1.groovy: 22: unable to resolve class DefaultIssueChangeHolder
 @ line 22, column 48.
   pdateValue(null, issue, mVal, new Defaul
                                 ^
5 errors
        at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:302)
        at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:858)
        at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:548)
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:497)
        at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:267)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:214)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getScriptClass(GroovyScriptEngineImpl.java:337)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:109)
        ... 186 more

1 answer

0 vote
Steven Behnke Community Champion Jun 03, 2015

You're trying to use ModifiedValue but you haven't imported it! 

https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/ModifiedValue.html

import com.atlassian.jira.issue.ModifiedValue

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 Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

706 views 6 13
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