Get the User Source the project is set to in perspective

Is there a way by which I can know which user source the project is using.

This is to add user using script to the user source which the project is currently set to.
If there is any change of user source then user should be added to that user source.
i.e.
system.user.addUser( "AcmeWest" , userToGet)

I want a variable to be used instead of “AcmeWest”

1 Like

Like this? :slight_smile:

image

1 Like

I tried this. But it doesn’t seem to work in perspective
When I tired to bind this to a parameter in a view it gives me error “Bad_Notfound”

  • Parameters

String userSource - The user source to add a user to. If set to an empty string, the function will attempt to use the project’s default user source (if called from a project).

2 Likes

Ah, perspective, how did I miss that…

1 Like

:sweat_smile: np

1 Like

This doesn’t seem to work although no error occurred

you also have to provide an empty string in the getNewUser()

this worked for me

userToGet = system.user.getNewUser("", "mTrejo")
  
# Add some contact info.
contactInfo = {"email":"mTrejo@acmewest.com","sms": "5551234"}
userToGet.addContactInfo(contactInfo)
userToGet.set("password", "thisIsMyPassword")
  
# Adds a user to the the AcmeWest usersource.
system.user.addUser("", userToGet)

1 Like

Thanks for that.
Yes I did the same.
But it’s not working :thinking:.

The user source is set in project properties>general right?

Yes that is correct

Are you calling the script from the project? (a button event)

Yes. I’m calling it on click of a button.

Also system.user.getUsers() does not take null string as an argument
Hence, I’m not able to iterate through all the users in the usersource and check if there already exits an user with same Email ID that I’m about to add.

its not null its ""

The example in the docs is this:
https://docs.inductiveautomation.com/display/DOC81/system.user.getUsers
Code Snippet
This example will print the first and last name of all users, using the default datasource.

users = system.user.getUsers("")
for user in users:
   print user.get('firstname') + " " + user.get('lastname')

Yes I used “” :smiling_face_with_tear:

Must be something related to the version of ignition I’m using

What version is that then?

I’m using 8.1.7

try upgrading then i guess

yes trying that