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.
Community moderators have prevented the ability to post new answers.
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 :) )
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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
com.atlassian.jira.user.UserPropertyManager#getPropertySet(user).get("phoneExt")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would slightly corrected it - that property name should be prefixed with "jira.meta." - ...get("jira.meta.phoneExt")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.