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())
}
Hi @Michael Bibby [Praecipio],
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.