issue get reporter in postfunction

T. Gutzeit June 17, 2016

I'm searching for syntax for issue get Reporter in postfunction.

 

I tried this

if(issue.getReporter() == 'xy'); { return true; }

if(issue.get('reporter') == 'xy'); { return true; }

 

It doesn't work.

 

How to write this condition in postfunction?

 

Thanks a lot.

Tatjana

 

 

 

6 answers

2 votes
Petar Petrov (Appfire)
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 17, 2016

Try this:

issue.reporter.name

You can also get the user key the same way.

1 vote
T. Gutzeit June 21, 2016

The right expression is in this Context:

if (issue.get("reporter").getUsername() == 'UserID')

{

return true;

}

 

That works.

Postfunction "Set Field Value to constant or Groovy expression Function" is from Addon "JIRA Misc Worklflow Extensions".

Answer from Support was this

"The "issue" variable holds a proxy to the Issue object, and only supports the "get" method. If you want to use JIRA's Issue object, you need to use the issueObject variable instead.
To get the reporter, you can use: issue.get("reporter"). That returns an ApplicationUser object, on which you can call "getUsername()" to get the username."

0 votes
T. Gutzeit June 17, 2016

I understand I tried this

if (issue.getReporter().getName() == ("Bob Smith")

if (issue.getReporter().getName() .equals("Bob Smith")

Doesn't working.

 

 

 

 

 

 

 

 

 

 

 

0 votes
Mahesh S
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 17, 2016


if(issue.getReporter().getName().equals('xy'))
{
return true
}

 

Mahesh S
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 17, 2016

Are you getting any error? What is the response?

Mahesh S
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 17, 2016

Your second approach is right!

if (issue.getReporter().getName() .equals("Bob Smith")

But, the error is the braces of if condition is not closed and there is a space before .equals.

if (issue.getReporter().getName().equals("Bob Smith"))

Try this now.

T. Gutzeit June 17, 2016

With braces or not unfortunately it doesn't work.

Mahesh S
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 17, 2016

Please compare and find your mistake. smile

Untitled.png

T. Gutzeit June 17, 2016

With space it also doesn't work. It's a Groovy script.

Mahesh S
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 17, 2016

Alright! Where are you trying this code now?

Please share a screenshot.

Mahesh S
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 17, 2016

Cool! Referring to @Nic Brough [Adaptavist]'s latest comment, try this script to get the right user name instead of the display name.

return issue.getReporter().getName()

Take the output of this and set it in the if condition's comparison.

Mahesh S
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 17, 2016

Have you tried this?

T. Gutzeit June 17, 2016

Yes I've tried doesn't work in this context it seems for me.

 

return issue.getReporter().getName() == 'username'
also
return issue.getReporter().getName().equals('username')

Mahesh S
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 17, 2016

Alright. Try this one now.

Go to JIRA Administration -> User Management -> Users. Search for your reporter. Click on Edit. It appears as this.

Untitled.png

Now consider the Username (Not the full name). Try the below script again. 

if(issue.getReporter().getName().equals('JIRAadmin'))
{
return true
}

It should work!

T. Gutzeit June 17, 2016

Yes ist should but i does not work.

So it is. I think in in the context of postfunction "Set field Value to constant or Groovy expression" there are some things that are special (but I don't know). Fact is this expression in different variants does not work.

 

 

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2016

If you want to use == to compare things, they usually need to be the same type of object.  Your code compares a "user" object with a string, which probably isn't going to work.  Either extract the name or login from the user to compare it, or make the string into a proper user.

In other words, something like

issue.getReporter().getName().equals("Bob")

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2016

If your code is now structurally correct, as we've all talked through, my next question is "are you comparing the right thing"?

A user object has many attributes - I've picked on getName() as probably the best one, but it might not be what you're comparing.

Let's take "confused Bob" as an example.  They log in as alice, have an email address of ConfusedBob@somewhere.com and a display name of Charlie Smith.  For Confused Bob here, getName will say "alice", but getDisplayName will give you "Charlie Smith".  I don't know what your XY string is trying to match...

T. Gutzeit June 17, 2016

I tried getName() with display name (real user in system, display name separated by space). Isn't it right?

I think the display name is not the best one. I think the Username would be good to compare or the mail-adress. But I don't know what JIRA writes in the field "reporter" (on screen you see the display Name in Issue).

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2016

No, see the end of my previous comment.

JIRA usually gives you the display name when it displays a user, but I think your instinct to use the login id is better than the display name (it can change, but rarely does)

T. Gutzeit June 17, 2016

I understand it with display name, user name and so on. But it doesn't matter which one I use, the result ist the same  not true.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 17, 2016

Ok, could you add some logging - specifically, what does this dump into the log?

System.out.println ( issue.getReporter().getName() )

0 votes
T. Gutzeit June 17, 2016

No doesn't work

 

I also tried this

if(issueObject.getReporter(). == 'xy'

The same doesn't work

Suggest an answer

Log in or Sign up to answer