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 votes
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

0 votes
Dieter Community Champion Jun 08, 2012

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,739 views 11 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot