Jump to content

adding expression on User custom attribute - gathering assigned projects


kristin

Recommended Posts

Hi there,

I'm trying to add a custom attribute on User entities using the expression type and have read through this page. Even adding something simple like `{self.username}` doesn't evaluate - see attached image. Am I doing something wrong?

My end goal is to gather the set of projects a user is assigned to. In python this being - `set(x['context']['project']['name'] for x in user['assignments'])`. This may be out of the scope of what expressions can do. But, we want to be able to add dashboard filters to only see users that are assigned to `x`, `y`, and `z` projects and can't do that currently. So adding a custom attribute to track a user's assigned projects is our workaround.

Screen Shot 2023-03-14 at 11.12.26 AM.png

Link to comment
Share on other sites

  • 3 weeks later...

Hi Kristin,

Thanks for reaching out, and apologies for the delayed response.

Unfortunately self if not supported for User Entities.  

That being said, you could always create a User Text custom attribute and map the variable used to query the projects the user has task assignments in.

 

Example below is a direct change I made through the terminal. I'm sure you could wrap this into an Event Listener.

 

user = session.query('User where username is "<ADD_USER_NAME_HERE>"').one()
  
some_list = set(x['context']['project']['name'] for x in user['assignments'])
  
new_list = ', '.join(some_list)
  
user['custom_attributes']['<ADD_CUSTOM_ATTRIBUTE_KEY_HERE>'] = new_list
  
session.commit()

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...