Hello.
I'm trying to adapt a script from the following website:
http://www.denizoguz.com/2013/06/29/jiraautomatically-linking-issues-with-a-script-during-create-transition/
Even though I don't know groovy, nor java, I somehow (thanks to google and atlassian developer site) made it to the point where script enters succesfully the last "if". Now I'm experiencing the problem than I can't find solution to. One of the last statements of the code throws following error:
2013-08-07 11:16:37,977 Thread-997 DEBUG test_user 676x14687x1 fm4ix2 ***.***.***.*** /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.PostFunction] Script executed this code
2013-08-07 11:16:37,977 Thread-997 ERROR test_user 676x14687x1 fm4ix2 ***.***.***.*** /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: IssueLinkTypeManager for class: Script13
2013-08-07 11:16:37,977 Thread-997 ERROR test_user 676x14687x1 fm4ix2 ***.***.***.*** /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: IssueLinkTypeManager for class: Script13
I'm afraid I need some help. Can anybody tell me what I'm doing wrong? I also don't understand this statement:
def issueLinkTypeManager = componentManager.getComponentInstanceOfType(IssueLinkTypeManager.class);
Am I wrong or is it trying to get some parameter of variable during definition of the very same variable? Or is IssueLinkTypeManager (with capital "i") some api interface, and issueLinkTypeManager just a variable?
What should I do to make the code work properly? Here is the whole script:
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
import org.apache.log4j.Category;
import com.atlassian.jira.issue.IssueManager;
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction");
log.setLevel(org.apache.log4j.Level.DEBUG);
def ComponentManager componentManager = ComponentManager.getInstance();
def customFieldManager = componentManager.getCustomFieldManager();
def parentTaskIDCF = customFieldManager.getCustomFieldObject('customfield_12101');//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);
if (isParentIssueValid) {
log.debug "Script executed this code";
def issueLinkManager = ComponentAccessor.getIssueLinkManager();
def issueLinkTypeManager = componentManager.
getComponentInstanceOfType(IssueLinkTypeManager.class);
def issueLinkType = issueLinkTypeManager.
getIssueLinkTypesByName('Relates').get(0);
def authenticationContext = componentManager.
getComponentInstanceOfType(JiraAuthenticationContext.class);
issueLinkManager.createIssueLink(
issue.id, parentIssue.id, issueLinkType.id, 1L, authenticationContext.user);
}
}
Thanks in advance!