Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Script Runner how to show Jira Account User Properties in Scripted Field

AndreH August 14, 2013

I need help creating a script for the Script Runner Plugin and a custom Scripted Field.

Custom Form - Helpdesk

(Custom User Picker Field) Customer <--- information is from the Jira Users

(Scripted Field) Users Location

I need help creating a script that will pull data from User Properties. In User Properties I have created several keys (public Location, public Address, public Phone, etc)

I need the Scripted Field to pull the public Location properties and disaplay it in the field.

Thanks in advance,

Andre

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Henning Tietgens
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.
August 15, 2013

Try this in your testsystem:

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 = "propertykey"

String propValue = null
User u = getCustomFieldValue('Customer')
if (u) {
    propValue = userPropertyManager.getPropertySet(u)?.getString('jira.meta.'+propKey)
}
return propValue

You first have to adapt propKey to the property key you want to get.

Henning

AndreH August 15, 2013

You are a life saver!!!!! THANK YOU!!!

0 votes
Tamir Lavi December 1, 2014

Hi! 

The code is great and simple but is didn't work for me because our users are from Active Directory. 

The error in that case is:

Cannot cast object '***' with class 'com.atlassian.jira.user.DelegatingApplicationUser' to class 'com.atlassian.crowd.embedded.api.User' dded.api.User'

So I fixed it by adding a different user type as follows:

import com.atlassian.jira.user.DelegatingApplicationUser
..
..
DelegatingApplicationUser u = getCustomFieldValue('Customer')

I hope my comment will help someone sometime somewhere...

Marcin Skwara June 10, 2018

Thanks @Tamir Lavi.

It helped me a lot.

I wonder is there any way to display this property but not from User from field but current user?

Henning Tietgens
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.
June 10, 2018

Sure, just use

u = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()

instead of

u = getCustomFieldValue('Customer')
Marcin Skwara June 11, 2018

Thanks @Henning Tietgens !

0 votes
AndreH August 14, 2013

I have tried the following script, however it is not working at all.

import com.atlassian.jira.web.action.admin.user.UserProperty;

import com.atlassian.jira.user.util.Users;

import com.atlassian.jira.issue.Issue;

String s="";

if getCustomFieldValue(11102)=Users()

{

s=s+getValue('public Location');

}

return s;

TAGS
AUG Leaders

Atlassian Community Events