Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to show Jira Account User Properties in Scripted Field

Vlad Fed December 10, 2019

Hi, community.

I need help creating a script for the Script Runner Field which will get data from reporter user properties.

This is what I could do but it gives me an error, I would be grateful for any help.

 

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.UserPropertyManager


String propertyKey = 'Phone'
String propertyValue = null


UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager()
User u = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
if (u) {
propertyValue = userPropertyManager.getPropertySet(issue.reporter).getString('jira.meta.Phone')
}

return propertyValue

 

1 answer

0 votes
Nic Brough -Adaptavist-
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.
December 10, 2019

Hard to say without seeing the error, there's two places I would look.

First, you don't need the "u" variable.  Scripted fields do not use the current user to generate their data, and the scripts run outside a user session.  You can lose the u = and if lines.

Second, are you sure the key jira.meta.Phone is set for every possible reporter?

Vlad Fed December 10, 2019

Regarding the second question, this key will be available for each reporter, because we have a limited list of them.

It produces such an error.
Regarding the first question, I have poor knowledge of scripting, could you tell me how best to implement this task?

image.png

Vlad Fed December 11, 2019

I fixed the script and it worked.

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.UserPropertyManager

UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager()

String propValue = null


propValue = userPropertyManager.getPropertySet(issue.reporter).getString('jira.meta.Phone')

return propValue


I would like to ask you how it can be supplemented so that a new value can be set through this field?

Like SKAdmin likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events