# Referring to database for keys of authenticated user roles

**URL:** <https://forum.inductiveautomation.com/t/referring-to-database-for-keys-of-authenticated-user-roles/75001>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [June 14, 2023, 8:16am UTC](https://forum.inductiveautomation.com/t/referring-to-database-for-keys-of-authenticated-user-roles/75001 "2023-06-14T08:16:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joseph\_Loh](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Loh](https://forum.inductiveautomation.com/u/Joseph_Loh)\
**Post date:** [June 14, 2023, 8:16am UTC](https://forum.inductiveautomation.com/t/referring-to-database-for-keys-of-authenticated-user-roles/75001/1 "2023-06-14T08:16:37Z")

</div>

Hi, new user here

I'm getting the following userroles from this table using  
ResultPydataset=system.db.runQuery("SELECT USERROLES FROM DATABASETABLE WHERE FUNCID='Force Bit'")

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/f/cfa2fb5a2bda6446c63e9125111bc328757e84d8.png)

I also have a dictionary in my scripting library:  
RoleDictionary = {  
'0': "Normal",  
'1': "Administrator",  
'2': "Engineers",  
'3': "MM",  
'4': "SS",  
'5': "CC",  
'6': "OO",  
'7': "AA",  
'8': "EO",  
'9': "Supervisor",  
'10': "Chargehand",  
'11': "Mechanic",  
}

How can I create a new dictionary that filters RoleDictionary based on the keys in ResultPydataset?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 14, 2023, 8:37am UTC](https://forum.inductiveautomation.com/t/referring-to-database-for-keys-of-authenticated-user-roles/75001/2 "2023-06-14T08:37:11Z")

</div>

Try this in Designer Script Console:

```auto
ResultPydataset = "1,2,9,10,11"
RoleDictionary = {
	'0': "Normal",
	'1': "Administrator",
	'2': "Engineers",
	'3': "MM",
	'4': "SS",
	'5': "CC",
	'6': "OO",
	'7': "AA",
	'8': "EO",
	'9': "Supervisor",
	'10': "Chargehand",
	'11': "Mechanic"
}

results = ResultPydataset.split(",")
print results

output = {}
for r in results:
	output[r] = RoleDictionary[r]
print(output)

```

Result:

```auto
>>> 
['1', '2', '9', '10', '11']
{'11': 'Mechanic', '1': 'Administrator', '2': 'Engineers', '9': 'Supervisor', '10': 'Chargehand'}

```

* * *

Tips:

1. You had a comma after "Mechanic". Python seems to handle it OK but it shouldn't really be there.
2. When pasting code use the \</\> button to format it, preserve indents and apply syntax highlighting. For inline bits of code enclose it in single ``backticks``.

---

<div class="post-metadata">

**Author:** ![Joseph\_Loh](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Joseph\_Loh](https://forum.inductiveautomation.com/u/Joseph_Loh)\
**Post date:** [June 14, 2023, 9:30am UTC](https://forum.inductiveautomation.com/t/referring-to-database-for-keys-of-authenticated-user-roles/75001/4 "2023-06-14T09:30:31Z")

</div>

It worked, especially after substituting my query line. Thanks!

---

<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:** [June 14, 2023, 4:25pm UTC](https://forum.inductiveautomation.com/t/referring-to-database-for-keys-of-authenticated-user-roles/75001/5 "2023-06-14T16:25:38Z")

</div>

> [@Transistor](#):
>
> - You had a comma after "Mechanic". Python seems to handle it OK but it shouldn't really be there.

Disagree. Trailing commas are a net positive for diffing of lines. With trailing commas, a new entry can be added in a list by only modifying one line. Without trailing commas, adding a new element to the end of a list of entries necessitates modifying two lines.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 14, 2023, 5:16pm UTC](https://forum.inductiveautomation.com/t/referring-to-database-for-keys-of-authenticated-user-roles/75001/6 "2023-06-14T17:16:22Z")

</div>

> [@paul-griffith](#):
>
> Disagree.

Can we still be friends?  
I understand your thinking. I did find it a problem in SQL query debugging, for example, and resorted to putting the commas on the start of lines so that they could be commented out without generating errors. It was much worse than a trailing comma.

---

<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:** [June 14, 2023, 5:20pm UTC](https://forum.inductiveautomation.com/t/referring-to-database-for-keys-of-authenticated-user-roles/75001/7 "2023-06-14T17:20:24Z")

</div>

Oh, don't get me started on SQL and how awful I consider the idea of ["fourth generation languages."](https://en.wikipedia.org/wiki/Fourth-generation_programming_language).

But in my opinion, if you're in an environment that _does_ support trailing commas, you should use them.
