# system.user.editUser just doubled the contact info I wanted to change

**URL:** <https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 1, 2020, 10:44pm UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610 "2020-04-01T22:44:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmahaffey](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tmahaffey/32/30949_2.png) [@tmahaffey](https://forum.inductiveautomation.com/u/tmahaffey)\
**Post date:** [April 1, 2020, 10:44pm UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/1 "2020-04-01T22:44:08Z")

</div>

Hello,

I followed the steps outlined in the guide here:

[https://docs.inductiveautomation.com/display/DOC80/system.user.editUser](https://docs.inductiveautomation.com/display/DOC80/system.user.editUser)

Here’s my code. As the title of this post suggests, I ended up doubling my contact info in the gateway, and I was trying to just alter it (change phone number, email, what-not)

```
username = self.view.params.username
# Retrieve the user we're going to edit
userToChange = system.user.getUser("UGC_MIDSTREAM_ACTIVE_DIR", username)
 
# Make a change to the user. In this case, we're adding some contact info

email = self.parent.getChild("FlexContainer_1").getChild("FlexContainer").getChild("emailEntry").props.text
sms = self.parent.getChild("FlexContainer_1").getChild("FlexContainer").getChild("smsEntry").props.text
phone = self.parent.getChild("FlexContainer_1").getChild("FlexContainer").getChild("phoneEntry").props.text
contactInfo = {"email": email,"sms": sms, "phone": phone}
userToChange.addContactInfo(contactInfo)
 
#Edit the user. Because the user object we're passing in has a user name, the function
 # already knows which user to edit
system.user.editUser("UGC_MIDSTREAM_ACTIVE_DIR", userToChange)	

self.getSibling("TextArea").refreshBinding('props.text')

```

Two of each now!!

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/55ba618476e231530e37d8d92cd7a1a2eb89e6d9.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 1, 2020, 11:21pm UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/2 "2020-04-01T23:21:55Z")

</div>

If you’re trying to edit information which is already in place, you should use `system.user.editUser()`. [Documentation](https://docs.inductiveautomation.com/display/DOC80/system.user.editUser).

Using `userToChange.addContactInfo()` is _adding_ information to what is already in place.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 1, 2020, 11:40pm UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/3 "2020-04-01T23:40:04Z")

</div>

> [@cmallonee](#):
>
> Using `system.user.addContactInfo()` is

Psst! No such thing...

---

<div class="post-metadata">

**Author:** ![tmahaffey](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tmahaffey/32/30949_2.png) [@tmahaffey](https://forum.inductiveautomation.com/u/tmahaffey)\
**Post date:** [April 2, 2020, 12:22am UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/4 "2020-04-02T00:22:57Z")

</div>

My intent was to edit contact info that was already in place.

---

<div class="post-metadata">

**Author:** ![tmahaffey](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tmahaffey/32/30949_2.png) [@tmahaffey](https://forum.inductiveautomation.com/u/tmahaffey)\
**Post date:** [April 2, 2020, 1:02am UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/5 "2020-04-02T01:02:26Z")

</div>

> [@pturmel](#):
>
> system.user.addContactInfo()

The documentation is a little unclear. the system.user.editUser() function only takes two parameters, and neither are contact information.

**Syntax**

**system.user.editUser(userSource, user)**

- Parameters

String userSource - The user source in which the user is found. Blank will use the default user source.

user user - The user to update.

- Returns

UIResponse - an object with lists of warnings, errors, and information returned after the edit attempt.

- Scope

Gateway, Vision Client, Perspective Session

I have the new contact information that wishes to replace the old existing contact info bunlded like this:  
contactInfo = {"email": email,"sms": sms, "phone": phone}

I'm still unclear how can I use these functions to update the contact info of a user?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 2, 2020, 12:48pm UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/6 "2020-04-02T12:48:08Z")

</div>

> [@tmahaffey](#):
>
> I’m still unclear how can I use these functions to update the contact info of a user?

That's because the documentation doesn't describe all of the features and functions of the `user` object that you get, modify, and then submit to `system.user.editUser()`.

This might help:

[http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.5/com/inductiveautomation/ignition/common/user/ContactInfo.html](http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.5/com/inductiveautomation/ignition/common/user/ContactInfo.html)

After getting the user, consider iterating through any existing contact info, looking for the type (email...) that you wish to update, then assigning to `.value`. If not found, use the .addContactInfo() method as before.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 2, 2020, 4:51pm UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/7 "2020-04-02T16:51:23Z")

</div>

This is a quick run without any checking logic, but I verified that it works for data that is already in place.

```auto
    user = system.user.getUser("UGC_MIDSTREAM_ACTIVE_DIR", username)
	contactInfo = user.getContactInfo()
	for piece in contactInfo:
		if piece.getContactType() == 'email':
			piece.setValue(email)
        if piece.getContactType() == 'sms':
			piece.setValue(sms)
        if piece.getContactType() == 'phone':
			piece.setValue(phone)
	system.user.editUser('default', user)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 2, 2020, 5:30pm UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/8 "2020-04-02T17:30:02Z")

</div>

I’d go a bit further:

```auto
user = system.user.getUser("UGC_MIDSTREAM_ACTIVE_DIR", username)
newInfo = {"email": email,"sms": sms, "phone": phone}
for ci in user.contactInfo:
    if ci.contactType in newInfo:
        # remove items from the dictionary as they are applied
        # to existing ContactInfo entries
        ci.value = newInfo.pop(ci.contactType)
# if anything is left in the dictionary, add it to the user
if newInfo:
    user.addContactInfo(newInfo)
system.user.editUser('UGC_MIDSTREAM_ACTIVE_DIR', user)

```

{ Untested… }

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 2, 2020, 5:33pm UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/9 "2020-04-02T17:33:15Z")

</div>

I wasn’t able to get `ci.value` working, and had to instead use the `ci.setValue()`. I’m not saying it doesn’t work - just that I had issues with it.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 2, 2020, 5:47pm UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/10 "2020-04-02T17:47:59Z")

</div>

Does Ignition register a custom wrapper for the ContactInfo type? Custom wrappers are expected to model all of the netbeans-style properties in their type dictionary. The standard jython wrapper for Java classes does this for you.

---

<div class="post-metadata">

**Author:** ![tmahaffey](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tmahaffey/32/30949_2.png) [@tmahaffey](https://forum.inductiveautomation.com/u/tmahaffey)\
**Post date:** [April 2, 2020, 6:22pm UTC](https://forum.inductiveautomation.com/t/system-user-edituser-just-doubled-the-contact-info-i-wanted-to-change/33610/11 "2020-04-02T18:22:11Z")

</div>

This script is working great. It allows me to edit the contact info, or if its not in place, it creates a new key value pair in the dictionary.
