Try this:
issue.reporter.name
You can also get the user key the same way.
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."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I understand I tried this
if (issue.getReporter().getName() == ("Bob Smith")
if (issue.getReporter().getName() .equals("Bob Smith")
Doesn't working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if(issue.getReporter().getName().equals('xy'))
{
return true
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you getting any error? What is the response?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
Please compare and find your mistake.
Untitled.png
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.
Alright! Where are you trying this code now?
Please share a screenshot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes I've tried doesn't work in this context it seems for me.
return
issue.getReporter().getName()
== 'username'return
issue.getReporter().getName()
.equals('username')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, could you add some logging - specifically, what does this dump into the log?
System.out.println ( issue.getReporter().getName() )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No doesn't work
I also tried this
if(issueObject.getReporter(). == 'xy'
The same doesn't work
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.