Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

script: how to get value of user property?

Jacques
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 4, 2012

I'm looking for a way to check wether a certain custom user property equals a certain issue value using a groovy script.

Assume the user has a phoneExtention property set to 876 and the the issue has a custom field called Allowed Extention which would contain just 1 phone extention.

How do I check: user.property.phoneExtention == issue.[Allowed Extension] in Groovy?

I have very little "Groovy" scripting knowledge. I want to use this in a transition condition (I have the script runner already installed).

Thanks for helping!

Jacques.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Jacques
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 5, 2012

hi Jamie and Jozef,

thanks for your help but in the setup I'm using I can't get this to work.

In order to run scripts I'm using this plugin: https://marketplace.atlassian.com/plugins/com.onresolve.jira.groovy.groovyrunner

It has an option to run a "live" script (without having it in a script file) and when I enter this line:

com.atlassian.jira.user.UserPropertyManager#getPropertySet(user).get("phoneExt")

it will return the following error: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script6.groovy: 1: unexpected char: '#' @ line 1, column 44. .jira.user.UserPropertyManager#getProper ^ 1 error

So I changed the # into a . (dot):

com.atlassian.jira.user.UserPropertyManager.getPropertySet(user).get("phoneExt")

This returns the error: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: user for class: Script7

It will return the same error if I change the last part into .get("jira.meta.phonExt")

Any idea what I'm doing wrong or what is missing?

(oh yes: the "current user" does have this "phoneExt" set :) )

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.
December 5, 2012

My code was just a pointer to APIs, not supposed to be working code.

def userPropertyManager = ComponentManager.getComponentInstanceOfType(UserPropertyManager.class)
userPropertyManager.getPropertySet(user).get("jira.meta.phone")

Like Tarun Sapra likes this
1 vote
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.
December 4, 2012

com.atlassian.jira.user.UserPropertyManager#getPropertySet(user).get("phoneExt")

Jozef Kotlár
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 5, 2012

I would slightly corrected it - that property name should be prefixed with "jira.meta." - ...get("jira.meta.phoneExt")

Like Ivan Torres-Candelaria likes this
TAGS
AUG Leaders

Atlassian Community Events