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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

809 views 2 19
Join discussion

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