Error creating a link for parent issue while creating a child issue

My reqiuirement is a follows:

1.We will introduce a 'Parent ID' label field for issue types.

2.we are making this field required, to ensure that users will be prompted to fill in the field

3.Upon creating a bug the Parent ID field will trigger a script that will create a link.This script will most likely be scriptrunner and the approach is based on: http://www.denizoguz.com/2013/06/29/jiraautomatically-linking-issues-with-a-script-during-create-transition/

Our Jira version is 6.1.5.

but the code applied on validators is not working properly. It give below exception in logs.

ERROR jiraad 861x2056x1 7ui5y0 10.202.29.46 /secure/QuickCreateIssue.jspa [groovy.canned.utils.ConditionUtils] javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: issueObject for class: com.atlassian.jira.issue.IssueImpl

Can you help in the code...

+++++++++++++++++++++++++++++
def parentTaskID = cfValues['Parent Task ID'];
if (parentTaskID == null || parentTaskID == '')

{ return true; }

else

{ def parentIssue = ComponentAccessor.getIssueManager(). getIssueObject(parentTaskID); def isValid = parentIssue != null && parentIssue.projectObject.key == issue.projectObject.key && (parentIssue.issueObject.name == 'Review Task' || parentIssue.issueObject.name == 'Test Task'); return isValid; }

Please suggest on the IssueObject property. How can this be exposed.

3 answers

What do you think parentIssue.issueObject is going to do?

I think you want parentIssue.issueTypeObject.name - but I'm not sure exactly what you are trying to do there.

ok well fix your immediate problem and use: parentIssue.issueTypeObject.name

Hi Jamie,

Thanks for your reply. what I am trying to do is mentioned in more detail at http://www.denizoguz.com/2013/06/29/jiraautomatically-linking-issues-with-a-script-during-create-transition/...

Thanks

Abhishek

Hello ,

The post function script mentioned below

+++++++++++++++

import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.IssueKey
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.*

def ComponentManager componentManager = ComponentManager.getInstance();
def customFieldManager = componentManager.getCustomFieldManager();
def parentTaskIDCF = customFieldManager.getCustomFieldObject('customfield_10105');//write your own custom field id here
def parentTaskID = issue.getCustomFieldValue(parentTaskIDCF);
if (parentTaskID == null || parentTaskID == '') {
return true;
} else {
def issueManager = ComponentAccessor.getIssueManager();
def parentIssue = issueManager.getIssueObject(parentTaskID);
def isParentIssueValid = parentIssue != null &&
parentIssue.projectObject.key == issue.projectObject.key &&
(parentIssue.issueTypeObject.name == 'Review Task' ||
parentIssue.issueTypeObject.name == 'Test Task');
if (isParentIssueValid) {
def issueLinkManager = ComponentAccessor.getIssueLinkManager();
def issueLinkTypeManager = componentManager.
getComponentInstanceOfType(IssueLinkTypeManager.class);
def issueLinkType = issueLinkTypeManager.getIssueLinkTypesByName('is blocked by').get(0);
def authenticationContext = componentManager.
getComponentInstanceOfType(JiraAuthenticationContext.class);
issueLinkManager.createIssueLink(
issue.id, parentIssue.id, issueLinkType.id, 1L, authenticationContext.user);
}
}

++++++++++++++++++++++++++++++++

and the exception retuned given below as ,

+++++++++++++++++++++++++++++

2014-06-10 12:34:26,043 http-bio-11000-exec-1 ERROR jiraad 754x3545x1 o9z41q 10.202.29.46 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
2014-06-10 12:34:26,043 http-bio-11000-exec-1 ERROR jiraad 754x3545x1 o9z41q 10.202.29.46 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Script post-function failed on null: /home/jira/linkissues.groovy
javax.script.ScriptException: javax.script.ScriptException: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:195)
at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
at com.onresolve.jira.groovy.GroovyRunner.run(GroovyRunner.java:62)

++++++++++++++++++++++++++++++++++++

please suggest.

Thanks

Can you use the proper code formatting tags from the toolbar... I can't even look at this.

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,245 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