It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

name 'customFieldManager' is not defined

Dmitriy Kalabin Jun 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
Thomas Venekamp Jun 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 Jun 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 Jun 12, 2017 • edited

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.

0 votes
Dmitriy Kalabin Jun 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 Jun 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.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Webinar invitation: Generate custom Jira Cloud PDF reports and exports

Jira may be a staple part of your workday, but your colleagues, customers, business partners or an auditor might need information presented in a different format, that is easy to access and read. And...

60 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you