Hi,
JIRA 7.13.0
Adaptavist ScriptRunner for JIRA 6.3.0
I am trying to get value of username from email address but getUserByEmail is not working and community answers suggested to use getUserByKey. However, i am struggling with this as well, could anyone please point out my mistake?
Please not that this small script is a part of a huge script.
Aim is to get value of display name from email. "owner" custom field is a single line text field which has user email address. Since, we use firstname.lastname for username so I have trimmed @domain.com which gives me user name and i need to generate displayName from username to use it along with username in the API call for confluence page creation from jira script post function
Script ==>
String username //= ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name
def fullname
def ownerObj = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Owner")
String ownerInitial = issue.getCustomFieldValue(ownerObj).toString()
println("Owner Initial is "+ownerInitial)
if(ownerInitial)
{
String user = ownerInitial
int index = ownerInitial.indexOf('@')
user = user.substring(0,index)
println("value of user is "+user)
//UserManager userManager = ComponentAccessor.userManager
UserManager userManager = ComponentAccessor.getUserManager()
username = userManager.getUserByKey(user)
println("Username is "+username)
fullname = username.displayName
println("Full name is "+fullname)
}
else
{
username = " "
fullname = " "
}
Logs ==>
Owner Initial is gottfried.mayer@domain.com
value of user is gottfried.mayer
Username is null
2020-08-21 22:25:34,282 https-jsse-nio-8553-exec-19 ERROR admin 1345x31387x1 13lhcsr 10.74.207.19 /secure/WorkflowUIDispatcher.jspa [c.o.s.jira.workflow.AbstractScriptWorkflowFunction] *************************************************************************************
2020-08-21 22:25:34,282 https-jsse-nio-8553-exec-19 ERROR admin 1345x31387x1 13lhcsr 10.74.207.19 /secure/WorkflowUIDispatcher.jspa [c.o.s.jira.workflow.AbstractScriptWorkflowFunction] Script function failed on issue: RMP-5828, actionId: 21, file: <inline script>
java.lang.NullPointerException: Cannot get property 'displayName' on null object
at Script377.run(Script377.groovy:237)
I would appreciate any guidance:)
Thanks
Bhupesh
I believe ownerInitial should be
def ownerInitial = issue.getCustomFieldValue(ownerObj) as ApplicationUser
importing https://docs.atlassian.com/software/jira/docs/api/8.5.4/com/atlassian/jira/user/ApplicationUser.html
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.