# Grab list of users from AD

**URL:** <https://forum.inductiveautomation.com/t/grab-list-of-users-from-ad/16261>\
**Category:** Ignition\
**Created:** [December 8, 2017, 4:32pm UTC](https://forum.inductiveautomation.com/t/grab-list-of-users-from-ad/16261 "2017-12-08T16:32:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [December 8, 2017, 4:32pm UTC](https://forum.inductiveautomation.com/t/grab-list-of-users-from-ad/16261/1 "2017-12-08T16:32:54Z")

</div>

Hey guys, I connected gateway with out Active Directory and can see the users their roles and email and phone numbers just fine, Now I want to see if I can grab the list of all the users on there so I can display it in a drop down so users can select a name and depending on the name selected they can send emails to that person. Tried to look around but didn’t find anything to help me. any suggestions?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 8, 2017, 4:36pm UTC](https://forum.inductiveautomation.com/t/grab-list-of-users-from-ad/16261/2 "2017-12-08T16:36:48Z")

</div>

[https://docs.inductiveautomation.com/display/DOC79/system.user.getUsers](https://docs.inductiveautomation.com/display/DOC79/system.user.getUsers)

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [December 11, 2017, 2:50pm UTC](https://forum.inductiveautomation.com/t/grab-list-of-users-from-ad/16261/3 "2017-12-11T14:50:37Z")

</div>

Thank you, I don’t know how I missed that one… 😖

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [December 14, 2017, 7:05pm UTC](https://forum.inductiveautomation.com/t/grab-list-of-users-from-ad/16261/5 "2017-12-14T19:05:09Z")

</div>

I have a followup question, I'm able to get what I want, now I'm stuck in adding my data to a data set table or a dropdown. I'm using the following code:

> users = system.user.getUsers("")  
> table = event.source.parent.getComponent('Table')  
> for user in users:  
> .......name = str(user.get(user.FirstName))+ " " +str(user.get(user.LastName))  
> .......email = str(user.get(user.Username))+"@gmail.com"  
> .......headers = ["Name", "Email"]  
> .......data =   
> .......data.append([name,email])  
> .......table.data = system.dataset.toDataSet(headers, data)

This is done on the scripting portion of a button, I'm able to write to the table but it only write one row, shouldn't this loop through every record and insert them to the table dataset?  
The dots show indentation.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 14, 2017, 7:16pm UTC](https://forum.inductiveautomation.com/t/grab-list-of-users-from-ad/16261/6 "2017-12-14T19:16:12Z")

</div>

Every iteration of the loop you start with an empty data list, append one user to it, then set that as the dataset on the table.

You should probably initialize the data list outside the loop.

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [December 14, 2017, 7:17pm UTC](https://forum.inductiveautomation.com/t/grab-list-of-users-from-ad/16261/7 "2017-12-14T19:17:22Z")

</div>

go figure… 😥 😂  
Thanks!!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 14, 2017, 8:38pm UTC](https://forum.inductiveautomation.com/t/grab-list-of-users-from-ad/16261/8 "2017-12-14T20:38:29Z")

</div>

And perform the assignment to table.data _ **after** _ the loop.

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [December 14, 2017, 9:15pm UTC](https://forum.inductiveautomation.com/t/grab-list-of-users-from-ad/16261/9 "2017-12-14T21:15:06Z")

</div>

thankfully I managed not to mess that part up lol…
