Currently I’m doing the feature of add new users through scripting but I have faced a problem which I’m not able to apply a role to a user through scripting but other column of User Source able to insert such as Username, Last Name, First Name.
Below is my sample code for add new user through scripting
userToGet = system.user.getNewUser("default", user_name)
userToGet.set("firstname", first_name)
userToGet.set(userToGet.LastName, last_name)
# Assign role to user
self.getSibling("Availability_Check").props.text = user_role
user_role = self.getSibling("Role_TextField").props.roles
userToGet.set("roles", user_role)
# Add contact info & password
phone_number = self.getSibling("Contact_No_TextField").props.text
entered_password = self.getSibling("Password_TextField").props.text
contactInfo = {"phone":phone_number}
userToGet.addContactInfo(contactInfo)
userToGet.set("password", entered_password)
# Adds a user to the the "default" usersource.
system.user.addUser("default", userToGet)
Anyone can help or give any advice. Thanks in advance.
If you do a dir() on the user object you got back, you should see a couple of functions, addRole() and addRoles(). The first takes a string (the name of the role) and the second takes a list of roles. I believe that will work – let me know if it doesn’t.
Hi Ms. may I know why the addContactInfo() can work which the contact no information are able to add to the user source and show it in the table but for role when I use addRoleInfo() it did not have any response but the other data such as username, first name , last name able to insert to the user source and show it in the table but only the role rows is show as N/A.
In conclusion, what I want to ask is does Ignition have the function of addRoleInfo() ?
Hi Ms., may I know why the addContactInfo() can work which the contact no information are able to add to the user source and show it in the table but for role when I use addRoleInfo() it did not have any response but the other data such as username, first name , last name able to insert to the user source and show it in the table but only the role rows is show as N/A.
In conclusion, what I want to ask is does Ignition have the function of addRoleInfo() ?