Script does not work after upgrading to JIRA 7.x

We upgraded JIRA and script runner and this code stopped working.  Has this happened to anyone?


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption

import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "debug statements"
//MutableIssue issue = (MutableIssue) ComponentAccessor.getIssueManager().getIssueObject("")
def issue = (MutableIssue) issue
log.debug "issue"
//getting and defining custom fields for future logic
def customFieldManager = ComponentAccessor.getCustomFieldManager()
log.debug "customFieldManager"
//finding the custom field Category object
def customField = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Category" }
log.debug "customField1"
//defining category as the value for Category a string
def category = (String) issue.getCustomFieldValue(customField)
log.debug "category"
//redefining 'customField' to the Internal Vendor POC object
// change from it.name == "Internal Vendor User" to it.name == "Vendor (Internal)" for PCS-21548
customField = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Vendor (Internal)" }
log.debug "customField2"
//defining internalVendor as the value from the Internal Vendor POC object
def ApplicationUser internalVendor = (ApplicationUser) issue.getCustomFieldValue(customField)
log.debug "appUser"
//allows for certain operations and functions to be used for future logic
def issueManager = ComponentAccessor.getIssueManager()
log.debug(category)

log.info("Internal Vendor:" + internalVendor)

//getting all issue links of type Location (to find the Site Bio)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueLinks = issueLinkManager.getOutwardLinks(issue.id)
log.info("Issue Found: " + issue.getKey())
def subElements = issueLinks.findAll {
issueLinks*.issueLinkType.name.contains('Location')
}
log.info("Sub Elements: " + issueLinks.size())

//fetching the vendor values from the Site Bio
if (issueLinks.size() > 0) {
def link = (IssueLink) issueLinks.get(0)
def myIssue = issueManager.getIssueObject(link.getDestinationId())
log.info("Site Bio found: " + myIssue.getKey())
ApplicationUser vendor1 = (ApplicationUser) myIssue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Video Vendor"))
ApplicationUser vendor2 = (ApplicationUser) myIssue.getCustomFieldValue(customFieldManager.getCustomFieldObjects(myIssue).find { it.name == "Access Control Vendor" })
ApplicationUser vendor3 = (ApplicationUser) myIssue.getCustomFieldValue(customFieldManager.getCustomFieldObjects(myIssue).find { it.name == "Intrusion Detection Vendor" })
log.info("Vendor 1:" + vendor1)
log.info("Vendor 2:" + vendor2)
log.info("Vendor 3:" + vendor3)

User assignee = issue.getAssignee()
log.info("Before If" + assignee)
//Checking the Assignee field, if it's empty we proceed, if not, the assignee remains'
if (assignee == null){
log.info("assignee is null " + assignee)
//if internal vendor is null, move to next if statement, else internal vendor = assignee
if (internalVendor == null){
//assigning the issue to the Project Lead
assignee = ApplicationUsers.toDirectoryUser(issue.getProjectObject().getProjectLead())
log.info("assignee = project lead " + assignee)
//Checking the category and the first vendor field to set the assignee
if (vendor1 != null && ["Video"].contains(category)) {
assignee = ApplicationUsers.toDirectoryUser(vendor1)
log.info("if vendor 1" + assignee)
//checking the category and the second vendor field to set the assignee
} else if (vendor2 != null && ["Access Control"].contains(category)) {
assignee = ApplicationUsers.toDirectoryUser(vendor2)
log.info("if vendor 2" + assignee)
} else if (vendor3 != null && ["Intrusion Detection"].contains(category)) {
assignee = ApplicationUsers.toDirectoryUser(vendor3)
log.info("if vendor 3" + assignee)
}
} else {
assignee = ApplicationUsers.toDirectoryUser(internalVendor)
log.info("if internal vendor" + assignee)
}
log.info("Assignee: " + assignee)
issue.setAssignee(assignee)

//issueManager.updateIssue(assignee, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

log.info("Issue Assignee: " + issue.getAssignee())
}
log.info("Assignee: " + assignee)
log.info("Issue Assignee: " + issue.getAssignee())
}

1 answer

This widget could not be displayed.

Hi @Michael Bibby,

  

In short, you are receiving errors because all ComponentManager methods have been removed. Instead, your code should utilize ComponentAcessor. You should remove ComponentManager and import ComponentAccessor instead:

import com.atlassian.jira.component.ComponentAccessor

To get the CustomFieldManager, you should access it through ComponentAcessor:

def customFieldManager = ComponentAccessor.getCustomFieldManager()

Until you make these modifications, your scripts will fail as they are not compatible with JIRA 7.

 

Please refer this guide.

https://scriptrunner.adaptavist.com/latest/jira/releases/UpgradingToJira7.html#_compatibility_with_jira_7

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

717 views 0 3
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