issue get reporter in postfunction

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

This widget could not be displayed.

Try this:

issue.reporter.name

You can also get the user key the same way.

This widget could not be displayed.

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."

This widget could not be displayed.

No doesn't work

 

I also tried this

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

The same doesn't work

This widget could not be displayed.

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")

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...

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).

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)

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.

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

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

This widget could not be displayed.
Mahesh S Community Champion Jun 17, 2016


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

 

Mahesh S Community Champion Jun 17, 2016

Are you getting any error? What is the response?

Mahesh S Community Champion Jun 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.

With braces or not unfortunately it doesn't work.

Mahesh S Community Champion Jun 17, 2016

Please compare and find your mistake. smile

Untitled.png

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

Mahesh S Community Champion Jun 17, 2016

Alright! Where are you trying this code now?

Please share a screenshot.

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

Have you tried this?

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 Community Champion Jun 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!

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.

 

 

This widget could not be displayed.

I understand I tried this

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

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

Doesn't working.

 

 

 

 

 

 

 

 

 

 

 

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

64 views 1 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you