Skip to main content
Version: 8.1

system.user.getNewUser

This function is used in Python Scripting.

Description

Creates a new user object. The user will not be added to the user source until addUser is called.

Client Permission Restrictions

Permission Type: User Management

Client access to this scripting function is blocked to users that do not meet the role/zone requirements for the above permission type. This function is unaffected when run in the Gateway scope.

Syntax

system.user.getNewUser(userSource, username)

Parameters

TypeParameterDescription
StringuserSourceThe name of the user source in which to create a user.
StringusernameThe username for the new user. Does not check if the username already exists or is valid.

Returns

User - The new user, as a User object. Refer also to the PyUser class.

Scope

Gateway, Vision Client, Perspective Session

Code Examples

Example #1
# Get new user.
userToGet = system.user.getNewUser("AcmeWest", "mTrejo")

# Add some contact info.
contactInfo = {"email":"mTrejo@acmewest.com","sms": "5551234"}
userToGet.addContactInfo(contactInfo)
userToGet.set("password", "mypassword")

# Adds a user to the AcmeWest usersource.
system.user.addUser("AcmeWest", userToGet)
Example 2
# Util for printing the responses.
def printResponse(responseList):
if len(responseList) > 0:
for response in responseList:
print "", response
else:
print " None"

# Make a brand new 'blank' user. Not saved until we, well, save.
username = event.source.parent.getComponent('Text Field').text
user = system.user.getNewUser("", "myAwesomeUser")

# Let's fill in some fields. Note we have two ways to access property names.
user.set("firstname", "Naomi")
user.set(user.LastName, "Nagata")
user.set("password", "1234567890")

# We can add contact info one at a time. Up to the script user to make sure the type is legit.
user.addContactInfo("email", "naomi@roci.com")

# We can add a lot of contact info.
contactInfo = {"email":"ignition_user@mycompany.com","sms": "5551212"}
user.addContactInfo(contactInfo)

# We can delete contact info. Only deletes if both fields match.
user.removeContactInfo("sms", "5551212")

# We can add a role. If the role doesn't already exist, user save will fail, depending on user source.
user.addRole("Mechanic")

# We can add a lot of roles.
roles = ["Administrator", "Operator"]
user.addRoles(roles)

# We can remove a role.
user.removeRole("Operator")

# We can add a schedule adjustment too.
date2 = system.date.now()
date1 = system.date.midnight(date2)
user.addScheduleAdjustment(date1, date2, False, "An adjustment note")

# We can make a bunch of adjustments and add them en-masse.
date3 = system.date.addDays(date2, -4)
adj1 = system.user.createScheduleAdjustment(date3, date2, True, "Another note")
adj2 = system.user.createScheduleAdjustment(date3, date1, False, "")
user.addScheduleAdjustments([adj1, adj2])

# and we can remove a schedule adjustment. All fields must match.
user.removeScheduleAdjustment(date1, date2, True, "Some other note")

# Finally, we will save our new user and print responses.
response = system.user.addUser("", user)

warnings = response.getWarns()
print "Warnings are:"
printResponse(warnings)

errors = response.getErrors()
print "Errors are:"
printResponse(errors)

infos = response.getInfos()
print "Infos are:"
printResponse(infos)