Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.



New_in
Version8.0.3



Scripting_function



Panel
titleDescription

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


Panel
titleClient 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.


Panel
titleSyntax

system.user.getNewUser(userSource, username)

  • Parameters

String userSource - The name of the user source in which to create a user.

String username - The username for the new user. Does not check if 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




Panel
titleCode Examples


Code Block
languagepy
titleCode Snippet
# 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 the AcmeWest usersource.
system.user.addUser("AcmeWest", userToGet)



Panel


Code Block
languagepy
titleCode Snippet
 # util for printing the reposonses
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("mechanicMechanic")
 
# we can add a lot of roles
roles = ["Administrator", "prisonerOperator"]
user.addRoles(roles)
 
# and we can remove a role
user.removeRole("prisonerOperator")
 
# 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 need to 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)




Panel
titleKeywords

system user getNewUser, user.getNewUser