Hi All -
We have been using an old version of JSU to copy a value from a text field (email address) to the Reporter Field. This means that the Reporter can be an email address instead of a user. I.e. "example@atlassian.com". Newer versions of JSU do not allow this feature and the old version of JSU still works but who knows for how long.
As a result, we have tried getting ScriptRunner to do this for us and have had no had luck. We are on the latest versions of ScriptRunner and JIRA Server. I have tried doing this with a post function and listener. I saw that the copy field value option does not include the Reporter field. Perhaps because it is a system field?
Trying old code examples does not work. Does anyone have any ideas?
You cannot store String value in a field expecting ApplicationUser. You're actually corrupting your database and it will eventually bite you back, I'm surprised as to how you were able to do so before and how invalid your jiraissue table is at this point. (Edit: I think I might have misunderstood your post, and the JSU function was storing the user, not the email string?)
What would be the correct way to do so would be to take the email address, find the user with this address, and save that user as the Reporter (and I could put together a snippet for that if you're not sure how to do it). Is there anything that you are doing with the Reporter afterward, why this isn't the option, what was the reason to store email instead of proper user in the first place?
Hi Radek,
What you are suggesting would work for us as well. The problem we are encountering is if a user tries to make a ticket using one of our special JIRA urls it is not capturing their information. Users without an account can also use these shortcut ticket creation URLs. When users use these urls it shows the reporter as "Anonymous". This prevents them from getting the email alerts.
I will play with the login settings to see and get back to you. Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, so I did a proof of concept that works on the Create (well it should in any transition):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.impl.GenericTextCFType
import com.atlassian.jira.bc.user.search.UserSearchService
import com.google.common.base.Strings
import com.atlassian.jira.user.ApplicationUser
final String TEXTFIELD_NAME = "Email Text Field"
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField textFieldCF = customFieldManager.getCustomFieldObjectsByName(TEXTFIELD_NAME).find {
it.getCustomFieldType() instanceof GenericTextCFType
}
if (textFieldCF == null) {
log.error("'" + TEXTFIELD_NAME + "' Custom Field not found on the system!")
return
}
String emailValue = issue.getCustomFieldValue(textFieldCF)
if (Strings.isNullOrEmpty(emailValue) || !emailValue.contains('@')) return //no value or not an email
UserSearchService userSearchService = ComponentAccessor.getUserSearchService()
ApplicationUser userMatchedByEmail = null
Iterable usersByEmail = userSearchService.findUsersByEmail(emailValue.trim())
Iterator iterator = usersByEmail.iterator();
while (iterator.hasNext()) {
userMatchedByEmail = iterator.next();
} // this should ideally ONLY EVER find a single user, otherwise up to you whether to use the last one or do nothing
if (userMatchedByEmail != null) {
MutableIssue mutableIssue = (MutableIssue) issue;
mutableIssue.setReporter(userMatchedByEmail);
}
else {
//no user found, do nothing? Or add a comment to issue to notify the assignee, or..
}
Note that the post-function order will matter:
Note I added extra 'Stores updates' function (this is out of box). I haven't tried it without it, but if memory serves it's needed, alternatively we could do the update in the script too, but.. the less the better.
I'm working here on the assumption that:
- the user in that email is not interacting with Jira, they are using some other portal?
- then this other portal takes their details, and it creates an issue in a project (probably some functional user doing that?)
In any case, if I've misunderstood some part, please let me know, I'm really a little thick today, not the brightest day.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks. I was able to run this without having to add stores updates to an issue and it worked.
The only problem we have is if the email address is not recognized then it defaults to "Anonymous". We would prefer it just shows their email address. But to your point, if that is a nono then we will try to force account creation before the user submits their ticket.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just to better understand - is there a specific reason for using the email address instead of the username? You might be able to use Automation for Jira to do this but I would have to test it out in my environment first.
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.