Jython post-function script

Kenneth Sekuterski December 14, 2020

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

0 votes
Evgeniy
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.
September 27, 2021

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