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

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 vote

Something like this:

import com.atlassian.jira.user.ApplicationUsers

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

untested

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.

Change

User u = getCustomFieldValue('Customer')

to

def u = getCustomFieldValue('Customer')

"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);

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

78 views 0 5
Read article

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