name 'customFieldManager' is not defined

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

Hello,

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

You are missing this line:

customFieldManager = ComponentAccessor.getCustomFieldManager()

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")

 

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.

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?

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
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,447 views 0 8
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you