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 votes

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 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,880 views 12 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