Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Jython post-function script

I'm currently working on a Jython post-function script that will copy the input of a field (separate Jira project) on a screen from a transition in Service Desk and make a copy of the Jira SD ticket to the selected project. The issue is when the input is left blank (none), it throws the following:

root cause: Traceback (most recent call last): File "/mnt/NewSanDatacenter/jira/jss/jython/workflow/clone_and_move.py", line 21, in <module> pkey = cfm.getCustomFieldObject('customfield_12019').getValue(issue).getKey() AttributeError: 'NoneType' object has no attribute 'getKey'

The script in question is written in

import com.atlassian.jira.issue;
from com.atlassian.jira.issue import ModifiedValue, DefaultIssueFactory
from com.atlassian.jira.issue.link import DefaultIssueLinkTypeManager

from com.atlassian.jira.component import ComponentAccessor;
from com.atlassian.jira.util import JiraUtils 

im = ComponentAccessor.getIssueManager();
am = ComponentAccessor.getJiraAuthenticationContext();
pm = ComponentAccessor.getProjectManager();
ilm = ComponentAccessor.getIssueLinkManager()
cfm = ComponentAccessor.getCustomFieldManager();

isf = JiraUtils.loadComponent(DefaultIssueFactory);
iltm = JiraUtils.loadComponent(DefaultIssueLinkTypeManager)

curUser = am.getLoggedInUser()

newissuet = isf.cloneIssue(issue)

pkey = cfm.getCustomFieldObject('customfield_12019').getValue(issue).getKey()

project = pm.getProjectObjByKey(pkey)

newissuet.setProjectObject(project)
newissuet.setReporter(curUser)
newissue = im.createIssueObject(curUser, newissuet)

linktype = iltm.getIssueLinkTypesByName('Relates')[0]
r = ilm.createIssueLink(issue.id, newissue.id, linktype.id, 1, curUser)

Any ideas what I should add here?

1 answer

Well, I think, question is not actual for current moment, but I'll try to answer :)

You are trying to get key from null object. Looks like that value of 'customfield_12019' for this issue does not exist. Check, is there any value or not.

And it's a good practice to use try - except, to avoid errors

Suggest an answer

Log in or Sign up to answer
TAGS

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