Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

name 'customFieldManager' is not defined

Dmitriy Kalabin June 12, 2017

Hello! I have plugin Scripting Suite, and I wrote script (Jython runner):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager


customField = customFieldManager.getCustomFieldObject("customfield_10105")

issue.setCustomFieldValue(customField, "15/02/2012 10:02")

 

But it is not working. Error - 

name 'customFieldManager' is not defined

system - JIRA Software 7.3.6.

what am I doing wrong?

2 answers

0 votes
Dmitriy Kalabin June 12, 2017

thank you, but now error - 

name 'issue' is not defined

 Can you suggest a book or an article where the process of writing scripts is described in more detail?

Thomas Venekamp
Contributor
June 12, 2017

Where do you execute the script? You can only access the field issue, if you use your script as a post-function.

If you want to execute your script in the Jython Runner, you have to get the issue with the IssueManager.

The Definitive Guide to Jython: Python for the Java Platform http://www.jython.org/jythonbook/en/1.0/

Here is the official JIRA API for your JIRA version: https://docs.atlassian.com/jira/7.3.6/

The wiki of jss gives you some basic information: https://quisapps.com/confluence/display/JSS/Scripting+Samples. But be aware, that the last edit is from 2010. You can search the internet for more information, or you ask your questions here in the community.

We moved to the script runner from adaptavist (but its paid). You get more help there, because more people use it and the community answers a lot of questions. The good part for you is, that if you can't or don't want to effort to buy the plugin, you can use the answered questions for your own code. You just have to change the groovy codes into jython code.

I hope that i could help you. If you have other questions, feel free to ask.

0 votes
Thomas Venekamp
Contributor
June 12, 2017

Hello,

as the log file tells you, the name 'customFieldManager' is not defined.

You are missing this line:

customFieldManager = ComponentAccessor.getCustomFieldManager()
Dmitriy Kalabin June 12, 2017

Anyway, an error (( - 

name 'ComponentAccessor' is not defined

Script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager


customFieldManager = ComponentAccessor.getCustomFieldManager()
customField = customFieldManager.getCustomFieldObject("customfield_10105")
issue.setCustomFieldValue(customField, "15/02/2012 10:02")

 

Thomas Venekamp
Contributor
June 12, 2017

I am sorry. You use the jython scripting suite. There you have to declare the imports differently.

from com.atlassian.jira.component import ComponentAccessor
from com.atlassian.jira.issue import CustomFieldManager


customFieldManager = ComponentAccessor.getCustomFieldManager()
customField = customFieldManager.getCustomFieldObject("customfield_10105")
issue.setCustomFieldValue(customField, "15/02/2012 10:02")

I hope this gives you the right imports to set the customfield.

But you have to test this, because I am not sure, if the customfield will accept the String as a Datetime Object.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events