Script runner 4.x API post function issues create sub task JIRA 7.3

Samir B January 12, 2017

Hi!

 

We are currently trying to upgrade from JIRA 6.2.x to JIRA 7.3. Currently we have especially with Script Runner some issues. 

We have a function that on a specific transition a sub task will be created and a person that is filled out in a custom field should be the assignee of the new sub task. 

For that we've put the following text into the "Additional issue actions" field:

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager

cfParent = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Team Lead')
parentMyFieldValue = transientVars["issue"].getCustomFieldValue(cfParent)
issue.setAssignee(ApplicationUsers.toDirectoryUser(parentMyFieldValue))

In 6.2 it works flawless, in JIRA 7.3 we are getting several errors:

 

For Line 3: The variable cfParent is undeclared

For line 4: The variable parentMyFieldValue is undeclared / Cannot find matching method

For line 5: the variable parentMyFieldValue is undeclared / And 2x Cannot find matching method

 

Hopefully someone can help me smile

Thanks in advance

 

1 answer

1 vote
adammarkham
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.
January 12, 2017

We're not yet compatible with JIRA 7.3. You can see the versions we are compatible with here.

Atlassian made some changes in JIRA 7 requiring you to change your scripts slightly.

Please try the following code for JIRA 7:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

def issue = issue as MutableIssue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfParent = customFieldManager.getCustomFieldObjectByName('Team Lead')
ApplicationUser parentMyFieldValue = issue.getCustomFieldValue(cfParent)
issue.setAssignee(parentMyFieldValue)

Line 3,4 - you need def in front of the variable name otherwise the type checker will complain. Line 5 - setAssignee takes an com.atlassian.jira.user.ApplicationUser instead of a com.atlassian.crowd.embedded.api.User.

Please see here for more information about how to change your scripts for JIRA 7.

Samir B January 12, 2017

Thank you for your help. Pasting your code brings on additional error in line 9.

Sheral Hewes January 18, 2017

Adam, when will the next version that supports 7.3 be available?

adammarkham
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.
January 18, 2017

Its going to be in the next few days, we are actively working on it as the top priority. We have had some issues with the rich text editor and the behaviours functionality. Apologies for the delay.

adammarkham
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.
January 18, 2017

Hi Samir, try this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser

def issue = issue as MutableIssue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cfParent = customFieldManager.getCustomFieldObjectByName('Team Lead')
ApplicationUser parentMyFieldValue = issue.getCustomFieldValue(cfParent)
issue.setAssignee(parentMyFieldValue)

Its because cfParent was not strongly typed. Although you see an error in the static type checker in these situations the script should still work.

Suggest an answer

Log in or Sign up to answer