Hi
I´ve got this script where I am trying to update the custom field "Groups" with the parent value "S D" and child value "T S":
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def fieldName = "Groups"
def field = getFieldByName(fieldName)
def customField = customFieldManager.getCustomFieldObjectByName(fieldName)
def fieldConfig = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(fieldConfig)
def parentOption = options.find {it.value == "S D"}
def childOption = parentOption?.childOptions?.find {it.value == "T S"}
field.setFormValue([parentOption.optionId, childOption.optionId])
But I keep getting this error:
2018-04-26 19:40:45,578 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ABC-5, actionId: 291, file: <inline script> groovy.lang.MissingPropertyException: No such property: ComponentAccessor for class: Script696 at Script696.run(Script696.groovy:1)
Any ideas what I am doing wrong?
Thanks so much,
KGM
Found out with a help of a friend. This works as a post function script:
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
Issue issueKey = issue
def issueManager = ComponentAccessor.getIssueManager()
def MutableIssue currentissue = issueManager.getIssueObject(issue.getKey())
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def textCf3 = customFieldManager.getCustomFieldObjects(currentissue).find {it.name == "The name of the custom field"}
def changeHolder = new DefaultIssueChangeHolder()
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
Map<String,Object> newValues = new HashMap<String, Object>()
Option parentOptionObj = optionsManager.findByOptionId(new Long(10010 i.e. the ID number of the value you want to update to));
Option childOptionObj = optionsManager.findByOptionId(new Long(10011 i.e. the ID number of the value you want to update to));
newValues.put(null,parentOptionObj)
newValues.put("1",childOptionObj)
textCf3.updateValue(null, currentissue, new ModifiedValue(currentissue.getCustomFieldValue(textCf3), newValues),changeHolder)
Can you post a screenshot?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I will quote myself in my first reply: "Any other errors similar to that will need a similar type of import."
Your error has to do with the customFieldManager.
Try these import statements:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.customfields.option.*;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I´ve added these and some more onto the import list (long list now) and am getting a new error:
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getFieldByName() is applicable for argument types: (java.lang.String) values: [Groups] at Script723.run(Script723.groovy:10)
Sorry, I´m not really a programmer (as is obvious), just trying to get through this "little" task :)
Thanks, KGM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try starting your script with
"import com.atlassian.jira.component.ComponentAccessor"
You need to import the ComponentAccessor class. Any other errors similar to that will need a similar type of import.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.