Forums

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

Script runner issue

Business Process Consulting
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 14, 2019

I have updated my jira to 8 and also script runner version. Our workflow conditions are stopped working

import com.atlassian.jira.issue.CustomFieldManagerimage.png
import com.atlassian.jira.component.ComponentAccessor;

import org.apache.log4j.Category;
import com.atlassian.jira.workflow.JiraWorkflow

JiraWorkflow workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue);
def wfd = workflow.getDescriptor()
def actionName = wfd?.getAction((int)transientVars["actionId"])?.getName();

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cfStatusDdetails = customFieldManager.getCustomFieldObjectByName("Status details")
issue.setCustomFieldValue(cfStatusDdetails,actionName)

Error - .getCustomFieldObjectByName("Status details")- Method doesn't exist. Replaced with suggestion method by getCustomFieldObjectsByName

Once i updated suggested method. It is failed in this line. 
issue.setCustomFieldValue(cfStatusDdetails,actionName)

 

Error i am getting attached in screen shot

 

 

2 answers

1 vote
Ilya Turov
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 14, 2019

getCustomFieldObjectsByName returns you a list of custom field objects, so if you are sure there exists one you should use getCustomFieldObjectsByName("field name")[0]

0 votes
Tarun Sapra
Community Champion
June 14, 2019

Hello @Business Process Consulting 

You have to fetch the custom field by "id" or by if you use byNames as shared by @Ilya Turov  then you will get a list and you will need to get the first element by calling "list.first()" on the returned list.

If you fetch custom field by id then that's the best way as it's agnostic to the custom field name 

customFieldManager.getCustomFieldObject("customfield_10005")

Suggest an answer

Log in or Sign up to answer