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
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
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

767 views 2 19
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