Yesterday I wrote a custom script that was returning a user based off a userName and it was working. This morning I ran the same code and it was returning Anonymous User. I simplified the code just to return me a static user and return it, and it still returns the Anonymous User.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser
ApplicationUser u = ComponentAccessor.getUserManager().getUserByKey("XXXX")
return u
Some things I have verified with the above code snippet:
* XXXX is my username in jira (what I use to login with - omitted for security)
* The Template type is "User Picker (single user)"
The interesting thing is that when I change the template type to "Text Field (multi-line)", and do the following:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser
ApplicationUser u = ComponentAccessor.getUserManager().getUserByKey("XXXX")
return u.getDisplayName()
I get what I expect. My full name
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser
ApplicationUser u = ComponentAccessor.getUserManager().getUserByKey("XXXX")
return u.getEmailAddress()
I get what I expect. I get my email address
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser
ApplicationUser u = ComponentAccessor.getUserManager().getUserByKey("XXXX")
return u.getUserName()
I get what I expect. My original input "XXXX"
Either something really bad is happening here, or I'm missing something really simple. Can someone please help out?
Very strange...I created a new scripted field, copied the first bit of code and it started working again. My only guess is that there is a bug when constantly switching the return type between Text Field (multi-line) and User Picker (which i've been doing for debugging).
Hi,
The reason for it returning Anonymous user is that you probably are incorrectly mismatching the Searcher and the Template.
If you have the template as "Users Picker" and the Searcher is set as "Free Text Searcher", then you would get Anonymous in your Field.
Because there's a mismatch between searcher and the template.
So if you are using User Picker template, set the Searcher for User picker as well.
And likewise for Free text template and searcher.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Although this is the most likely thing that was wrong (and I found so in other community questions), I played around with it for multiple hours switching it between user picker, and free text searcher. and it still returned Anonymous user when using "User Picker". I also verified that the type returned was strongly typed as an ApplicationUser. as I mentioned above, I think there was something corrupt in the database with this 1 scripted field, because once I spun up a new one, copy/pasted the embedded code, it started working again as expected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Phillips, I´m having the same problem here.... did you find any solution?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Esteban Diaz. I had a similar issues that was resolved by updating the Custom Field Search Template. I posted the answer to my own question here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.