For loop binding Perspective

Hi all,

I have a question about for loop in bindings, is this possible?

I tried a for loop for looping through a list of users and check if the user has a role, but it doesn’t work.

I tried the following code:

for x in range(len(self.session.props.auth.user.roles)):
if self.session.props.auth.user.roles == ‘Operator’:
return ‘true’
else:
return ‘false’

I’m thinking about the performance because it loops continuous, which means the performance degrade, but I don’t know if this is right?

Are you trying to use Python in an expression binding? That won’t work. You can only use Expression Functions - Ignition User Manual 8.1 - Ignition Documentation.


Essential tip: use the </> code formatting button to format your code and preserve indentation. This is essential for Python. Can you edit your question to fix it? Thanks.

1 Like

Think you just want to use the hasRole expression - hasRole - Ignition User Manual 8.0 - Ignition Documentation

4 Likes