Its possible to use Workflow GroovyScript validator to validate if Current User is the Project Lead?

André Mendonça June 24, 2014

Hi All,

I want to know if its possible to use the Groovy Script Runner to check if the current user is the current project Lead in a workflow condition to Close an issue.

I'm trying to do using the "Simple Scripted condition" as a Workflow condition.

currentUser == issue.getProjectObject().getLeadUser()

But without results =\

So, it's possible? Any Tips?

Thanks in Advance for the help.

4 answers

1 accepted

1 vote
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.
June 24, 2014

Looks ok to me... try it in the condition tester, and prefix with assert, ie:

assert currentUser == issue.getProjectObject().getLeadUser()

Paste back here what it says... maybe they are different types of User.

André Mendonça June 24, 2014

This is what i get:

assert currentUser == issue.getProjectObject().getLeadUser()
       |           |  |     |                  |
       512300:10001|  IST-7 Project: IST       512300:10001
                   false
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.
June 25, 2014

That's interesting..

If you get a sec can you try:

assert currentUser.getClass().name == issue.getProjectObject().getLeadUser().getClass().name
0 votes
Noel John December 13, 2019

related to this,

i used currentUser == issue.getProjectObject().getProjectLead() on the workflow create validation to restrict only project lead to create under one issue type and it worked.

0 votes
André Mendonça June 24, 2014

This Worked:

issue.getProjectObject().getLead().equals(currentUser)

Thanks

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.
June 24, 2014

I have no idea why that works. Is it an old version of jira?

André Mendonça June 25, 2014

Actually we're using the Jira 6.1.5.
I found this weird too.

If they're diferent types of user, my code isn't supposed to work right?

And, as you asked, here are the assert with the Class name.

assert currentUser.getClass().name == issue.getProjectObject().getLeadUser().getClass().name
       |           |          |    |  |     |                  |             |          |
       512300:10001|          |    |  IST-7 Project: IST       512300:10001  |          com.atlassian.jira.crowd.embedded.ofbiz.OfBizUser
                   |          |    false                                     class com.atlassian.jira.crowd.embedded.ofbiz.OfBizUser
                   |          com.atlassian.jira.user.BridgedDirectoryUser
                   class com.atlassian.jira.user.BridgedDirectoryUser
 Thanks a lot for your help Jamie Echlin.
Sverre Moe August 20, 2015

I tried both and neither worked: Add condition => Script condition => Custom script condition Inline script content JIRA 6.4.5

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.
August 22, 2015

for the code above you need "Simple Script Condition", not custom.

0 votes
André Mendonça June 24, 2014

Well, after posting the question here i solutioned my own problem.

The anwser, if anyone need:

On condition field:

currentUser == issue.getProjectObject().getLeadUser()

Suggest an answer

Log in or Sign up to answer