groovy script issue

this days i tested about jira upgrade from ver 4.4.5(standalon, redhat) to 5.0.5(war, open suse, vm enviroment)

there is a groovy script issue.

this script is work well at jira version 4.4.5. but make a issue at jira version 5.0.5

//===========================================================

import com.atlassian.jira.user.util.UserUtilImpl

//import com.atlassian.core.user.GroupUtils

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.groups.DefaultGroupManager

import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext

//log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
//log.debug ("test " + "test")
//log.error "error"

def allowGroupStr = "crowd-project"
def addUsers = "User to grant"
def addGroups = "Group to add"
String commentValue = ""

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

CustomField customFieldaddUsers = customFieldManager.getCustomFieldObjectByName( addUsers )
println "***" + customFieldaddUsers +"***"
addUsersFieldVal = issue.getCustomFieldValue( customFieldaddUsers )
println "***" + addUsersFieldVal + "***"
CustomField customFieldaddGroups = customFieldManager.getCustomFieldObjectByName( addGroups )
addGroupsFieldVal = issue.getCustomFieldValue( customFieldaddGroups )

//IssueFactory issueFactory = componentManager.getIssueFactory()
//MutableIssue issue = issueFactory.getIssue()
//User currentUser = componentManager.getJiraAuthenticationContext().getUser()
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

println "*** test code ****"
User userToAdd1 = UserUtils.getUser( "test11" )

println "***test" + userToAdd1 +" **test**"

===========================================================//

from this script

fail to getCustomFieldValue and getUser.

the error log is

//============================================================

***User to grant***
***[com.atlassian.crowd.embedded.ofbiz.OfBizUser@ab3680ae]***
*** test code ****
***testcom.atlassian.crowd.embedded.ofbiz.OfBizUser@ab3680ae **test**

=============================================================//

I don't know why this error message is printed.

do you know the solution?

plz help me :)

2 answers

0 vote
Mizan Community Champion Jun 08, 2012

There are some API changes in 5.0 onwards . Have a look at this .

You will have to update your script accordingly to the updated API

Hi Jiyoung,

I have made some changes in your code to make it run on Jira 5

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.crowd.embedded.api.User;


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.groups.GroupManager;

import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext


import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.fields.CustomField;

import com.atlassian.jira.issue.Issue;



 

//log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
//log.debug ("test " + "test")
//log.error "error"


def allowGroupStr = "crowd-project"
def addUsers = "User to grant"
def addGroups = "Group to add"
String commentValue = ""

// get all managers if possible using ComponentAccessor
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

// please use this in Jira 5
GroupManager groupManager = ComponentAccessor.getGroupManager()

CustomField customFieldaddUsers = customFieldManager.getCustomFieldObjectByName( addUsers )
println "***" + customFieldaddUsers +"***"
List addUsersFieldVal = issue.getCustomFieldValue( customFieldaddUsers )
addUsersFieldVal.each() {println "*** " + it.getName()}

println "***" + addUsersFieldVal + "***"
CustomField customFieldaddGroups = customFieldManager.getCustomFieldObjectByName( addGroups )
addGroupsFieldVal = issue.getCustomFieldValue( customFieldaddGroups )

//IssueFactory issueFactory = componentManager.getIssueFactory()
//MutableIssue issue = issueFactory.getIssue()
//User currentUser = componentManager.getJiraAuthenticationContext().getUser()

User currentUserObject = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

println "*** test code ****"
User userToAdd1 = ComponentAccessor.getUserUtil().getUserObject("test11" )

// use getName(). toString() is not implemented anymore for crowd user objects
println "***test" + userToAdd1.getName() +" **test**"
println "***current user" + currentUserObject.getName() +" **current user**"

thanks so much. I solve that issue ^^

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
Posted 12 hours ago in Jira

We want to know what Jira Service Desk apps you're using!

Hi Community! My name is Amir and I’m on the Jira Service Desk product marketing team at Atlassian. Our team would love to understand how you’re leveraging our ecosystem for Jira Service Desk. Wha...

35 views 0 5
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