It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script does not work after upgrading to JIRA 7.x

Michael Bibby Dec 19, 2017
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

1 accepted

1 vote
Answer accepted
Laxmi Dec 19, 2017

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Marketplace Apps & Integrations

Demo Den Ep. 4: Continuous Integration with CircleCI & Jira Software

Get ready! Demo Den Episode 4 is coming your way on Tuesday, May 28, 2018 with a Continuous Integration and Delivery special demo. CircleCI Director of Solutions Engineering, Eddie Webb will show us ...

707 views 0 4
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you