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

mc March 16, 2015

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 votes
Steven F Behnke
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.
June 3, 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