Im trying to make a simple post function with scriptrunner groovy.
All I want is to set a value of a field when a list field has a specific value. But it seems like the documented functions doesnt exist.
"issue.setDescription(cfValues['Bug Priority']?.value)" gives
groovy.lang.MissingPropertyException: No such property: cfValues
"def myValue = getFieldById("customfield_10128")" gives cannot find find matching method.
How can I get the value of my list field and use it in a if case to do something...
Try to understand how the code works using CustomField and CustomFieldManager classes. refer this https://community.atlassian.com/t5/Jira-Core-questions/Scriptrunner-post-function-Update-a-custom-text-field-with/qaq-p/267648#M17181
Else plz share your complete code so that I can help you out.
Thanks. i got it to work with this code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField field1 = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Bug Priority"}
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
String field1Value = (String)issue.getCustomFieldValue(field1)
def checkbox = customFieldManager.getCustomFieldObjectByName("Flagged")
def fieldConfig = checkbox.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Impediment", null)
if (field1Value == "P1"){
issue.setCustomFieldValue(checkbox, [option])
}
But I still dont understand why I couldent use cfValues to fetch the field1 value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What exactly are you trying to write?
def myValue = getFieldById("customfield_10128") is from behaviours
issue.setDescription(cfValues['Bug Priority']?.value) is from worflow functions
Where do you type your code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
its a post function as the headline says.
If getFieldById only works for behaviours then that explains it.
But why does it complain on cfValues? If I click the little '?' button cfValues is clearly an object that I can use to fetch values of custom fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It could be a static compilation error. Just run your code
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.