I am having issues with Scripted Fields.
I recently upgraded JIRA 6.4.13 to JIRA 7.2 and I have several Scripted Fields that no longer function.
My scripted fields are pulling data from a JIRA users Properties and displays this on the Issue Details section.
Example of User Properties:
User - John Smith
Properties
Key public Phone
Value (800) 555-1212
Here is the code for the Scripted Field
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.UserPropertyManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.ProjectService
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.core.util.DateUtils
UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager();
String propKey = "public Phone";
String propValue = null;
def u = getCustomFieldValue('Customer')
if (u) {
def dirUser = ApplicationUsers.toDirectoryUser(u)
propValue = userPropertyManager.getPropertySet(dirUser)?.getString('jira.meta.'+propKey);
}
return propValue;
Errors
LOGS
Time (on server): Tue Sep 13 2016 10:40:55 GMT-0700 (Pacific Daylight Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2016-09-13 10:40:55,628 ERROR [customfield.GroovyCustomField]: *************************************************************************************
2016-09-13 10:40:55,629 ERROR [customfield.GroovyCustomField]: Script field failed on issue: HD-149012, field: Customer Phone
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.user.DefaultUserPropertyManager.getPropertySet() is applicable for argument types: (com.atlassian.jira.user.BridgedDirectoryUser) values: [ksmith:10001]
Possible solutions: getPropertySet(com.atlassian.jira.user.ApplicationUser), getProperties()
at Script665.run(Script665.groovy:20)
PAYLOAD
Issue: HD-149012
{
"customField": "Customer Phone (com.atlassian.jira.issue.fields.ImmutableCustomField)",
"issue": "HD-149012 (com.atlassian.jira.issue.IssueImpl)",
"log": "org.apache.log4j.Logger@d0e3d93",
"componentManager": "com.atlassian.jira.ComponentManager@7f1bab55",
"getCustomFieldValue": "groovy.lang.Closure",
"enableCache": "groovy.lang.Closure"
}
And Screen shot of Errors
Inline Script Errors.png
Thank you for your assistance
You don't need this anymore:
def dirUser = ApplicationUsers.toDirectoryUser(u)
as users have been normalised, and tfft.
So just delete that line and use "u" instead of dirUser.
That's what this is trying to tell you:
Possible solutions: getPropertySet(com.atlassian.jira.user.ApplicationUser)
Hi I changed the code to
UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager(); String propKey = "public Phone"; String propValue = null; def u = getCustomFieldValue('Customer') if (u) { propValue = userPropertyManager.getProperties(u)?.getString('jira.meta.'+propKey); } return propValue;
How ever there is still the error for the getProperties
New Error.png
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe you want getPropertySet(u)
. getProperties()
is going to call the default Groovy object method sig with that name.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager(); String propKey = "public Phone"; String propValue = null; def u = getCustomFieldValue('Customer') if (u) { propValue = userPropertyManager.getPropertySet(u)?.getString('jira.meta.'+propKey); } return propValue;
It is set to getPropertySet(u), however I am still getting errors. What am I missing?
Error3.png
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's just a case of the static type checker failing to understand Groovy's duck typing. Since your script declares the u
variable using def
, the static type checker assumes that it's a java.lang.Object, which is not the type required by the getPropertySet
method. That said, it should still work by the power of Groovy. We'd like the code editor to be considerably more helpful in this regard, but it's just not there yet.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I checked an issue withe the field and it is functioning without error.
So, the error I see can be ignored at the moment until maybe a later release of the plugin?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You bet. See https://scriptrunner.adaptavist.com/latest/jira/#_static_type_checking for a little more info on the static type checker.
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.