Good afternoon, all!
I’m working on placing a button on a report form for emailing the data using system.report.executeAndDistribute. This works for a static user, but I can’t seem to locate a method for getting the currently logged-in user’s email address.
Probably simple…but the method doesn’t appear to be well documented in the manuals.
Any help or advice is greatly appreciated!
I would get the current username using the tag “[System]Client/User/Username” or the script function system.security.getUsername(). Then you can use system.user.getUser to get a user object that has the method getContactInfo().
I didn’t test any of this, so if you have any trouble I can pop open a designer and write some code.
Yes, a code snippet would be helpful. I can get username from system.security.getUsername() just fine, but receive an error for “object has no attribute ‘getContactInfo’” error.
Appreciate the assistance!
Did you do the step where you take that username and get a User object from
username = system.security.getUsername()
user = system.user.getUser('default', username)
userContact = user.getContactInfo()
#Some fallback value in case the user doesn't have a registered email
userEmail = ""
for x in range(len(userContact)):
if userContact[x].contactType == 'email':
userEmail = userContact[x].value
userContact is a java array of contact objects. I couldn’t think of a better way to iterate over it, but it should usually be a sort list.
Thank you again. This worked well!!
userEmail = next((ci.value for ci in user.contactInfo if ci.contactType == "email"), "")
That’s perfect. I like to use questions like this as exercises for myself, I’ve learned a lot from it–and from seeing your guys’ golf scores