Scripted Fields for JIRA 7.2 Syntax Issue (Adaptavist ScriptRunner for JIRA)

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.

  • JIRA Server - Version 7.2.0
  • Adaptavist ScriptRunner for JIRA Version: 4.3.6

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

 

 

1 answer

1 accepted

This widget could not be displayed.

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

I believe you want getPropertySet(u)getProperties() is going to call the default Groovy object method sig with that name.

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

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.

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 bet. See https://scriptrunner.adaptavist.com/latest/jira/#_static_type_checking for a little more info on the static type checker.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

126 views 1 3
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