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

AndreH September 13, 2016

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

0 votes
Answer accepted
JamieA
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.
September 13, 2016

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)

AndreH September 13, 2016

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

Jonny Carter
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.
September 14, 2016

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

AndreH September 15, 2016
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

Jonny Carter
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.
September 15, 2016

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.

AndreH September 15, 2016

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?

Jonny Carter
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.
September 15, 2016

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
TAGS
AUG Leaders

Atlassian Community Events