Send Email to current user via system.report.executeAndDistribute

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!

Thanks,

John

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().

https://docs.inductiveautomation.com/display/DOC80/system.user.getUser

I didn’t test any of this, so if you have any trouble I can pop open a designer and write some code.

Thanks.

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 system.user.getUser?

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
		break
print userEmail

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.

1 Like

Thank you again. This worked well!!

1 Like

:golfing_man:

userEmail = next((ci.value for ci in user.contactInfo if ci.contactType == "email"), "")
1 Like

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 :wink:

1 Like