Scripted Fields - Upgrade to Jira 6.2.2 breaks existing Crowd API statements

AndreH April 20, 2014

I am currently testing an upgrade from Jira 5.2.7 to Jira 6.2.2

In the jira 5.2.7 we have several scripted fields that ready the Jira Users Account Properties meta-data and displays it in a Scripted Field on a issue.

For Example - in the user account - Jira User. Defined property (Manager - John Doe)

Here is the currently working Jira 5.2.7 scripted field -

import com.atlassian.crowd.embedded.api.User;

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.user.UserPropertyManager;

UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager();

String propKey = "public Manager";

String propValue = null;

User u = getCustomFieldValue('Customer')

if (u) {

propValue = userPropertyManager.getPropertySet(u)?.getString('jira.meta.'+propKey);

}

return propValue;

Now, when I upgraded Jira to 6.2.2, this field no longer works and returns an error -

javax.script.ScriptException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'ahughes(ahughes)' with class 'com.atlassian.jira.user.DelegatingApplicationUser' to class 'com.atlassian.crowd.embedded.api.User' A stacktrace has been logged.

Did Jira 6.2.2 change the Crowd API statement? Is there a 6.2.2 version that would work?

Thanks in advance,

Andre


1 answer

1 accepted

0 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 21, 2014

Something like this:

import com.atlassian.jira.user.ApplicationUsers

if (u) {
   def dirUser = ApplicationUsers.toDirectoryUser(u)
   ...
   then use dirUser not u

untested

AndreH April 21, 2014

I tried changing it to the following -

import com.atlassian.jira.user.ApplicationUsers;

import com.atlassian.crowd.embedded.api.User;

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.user.UserPropertyManager;

UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager();

String propKey = "public Manager";

String propValue = null;

User u = getCustomFieldValue('Customer')

if (u) {

def dirUser = ApplicationUsers.toDirectoryUser(u);

propValue = userPropertyManager.getPropertySet(u)?.getString('jira.meta.'+propKey);

then use dirUser not u;

}

return propValue;

However it still returns the error -

javax.script.ScriptException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'ahughes(ahughes)' with class 'com.atlassian.jira.user.DelegatingApplicationUser' to class 'com.atlassian.crowd.embedded.api.User' A stacktrace has been logged.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 21, 2014

Change

User u = getCustomFieldValue('Customer')

to

def u = getCustomFieldValue('Customer')

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 21, 2014

"then use dirUser not u;"

was a comment for you not code.

To be more specific, change

propValue = userPropertyManager.getPropertySet(u)?.getString('jira.meta.'+propKey);

to

propValue = userPropertyManager.getPropertySet(dirUser)?.getString('jira.meta.'+propKey);

AndreH April 21, 2014

Thank you it worked - here is the final version -

import com.atlassian.jira.user.ApplicationUsers;

import com.atlassian.crowd.embedded.api.User;

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.user.UserPropertyManager;

UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager();

String propKey = "public Manager";

String propValue = null;

def u = getCustomFieldValue('Customer')

if (u) {

def dirUser = ApplicationUsers.toDirectoryUser(u)

propValue = userPropertyManager.getPropertySet(dirUser)?.getString('jira.meta.'+propKey);

}

return propValue;

Suggest an answer

Log in or Sign up to answer