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
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?
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.