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

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

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.

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

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

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.

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
Community showcase
Published Nov 29, 2018 in Jira

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