Edit Contact info for existing users

I have the following code for adding contact info when creating a new user…

contactInfo = {"email":self.getSibling("txtEmail").props.text}
userToChange.addContactInfo(contactInfo)

How would you be able to change this so it can edit existing contact info instead of adding new info?

The User object appears to have a .setContactInfo() method that allows you to rewrite it’s internal contact info. However, it expects a list of ContactInfo typed objects which isn’t super friendly or obvious. However, code like this should work for ya:

from com.inductiveautomation.ignition.common.user import ContactInfo

contactInfo = ContactInfo('email','test@test.com')
user = system.user.getUser('default','admin')
user.setContactInfo([contactInfo])
system.user.editUser('default',user)
1 Like

Also, if you retrieve a ContactInfo from an existing user, you can setValue or setContactType to modify it into a different object - then reassign it to the user and commit the edited user.

2 Likes

Thanks, that worked out.