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


I followed the steps outlined in the guide here:

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}
#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)	


Two of each now!!

1 Like

If you’re trying to edit information which is already in place, you should use system.user.editUser(). Documentation.

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

Psst! No such thing…

1 Like

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

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


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?

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:

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.

1 Like

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

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

I’d go a bit further:

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:
system.user.editUser('UGC_MIDSTREAM_ACTIVE_DIR', user)

{ Untested… }

1 Like

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.

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.

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.

1 Like