Forums

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

scriptrunner post-function syntax help

Torbjörn Richter April 17, 2018

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... 

 

 

 

2 answers

1 vote
Mahesh S
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.
April 17, 2018

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.

Torbjörn Richter April 17, 2018

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.

0 votes
Alexey Matveev
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.
April 17, 2018

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?

Torbjörn Richter April 17, 2018

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.

Alexey Matveev
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.
April 17, 2018

It could be a static compilation error. Just run your code

Torbjörn Richter April 17, 2018

i did. the error is first shown in the execution log. 

image.png

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events