Accessing HumanUser login field on API .find()

Hi there! How do I access login field for a HumanUser on a task_assignee multi-entity? From the documentation, I thought it would be like this, but I’m not having any luck.

sg.find(entity_type='Task', filters=[['task_assignees', 'is_not', None]], fields=['task_assignees', 'task_assignees.HumanUser.login',])


Hi Dynendal,

Welcome to the forums, unfortunately the task_assignees field is a multi-entity field and cannot be searched through as it can return multiple values such as more than one person or a group/s.

You will need 2 commands, one to find the human user/ users, and then in that list of returned users/groups, you will need to have a lookup on the login value.

For example;

# get all tasks with someone assigned
tasks = sg.find("Task", filters=[["task_assignees", "is_not", None]], fields=["task_assignees"])
# build a filter that will find all the user's based on the all the task's task_assignees fields.
user_filters = []
for a_task in tasks:
    for a_user in a_task["task_assignees"]:
        user_filters.append( ["id", "is", a_user["id"]] )
filters = [{"filter_operator": "any", "filters": user_filters}]
# which will generate something like this
# > [{'filter_operator': 'any', 'filters': [['id', 'is', 18], ['id', 'is', 21], ... ]}]
users = sg.find("HumanUser", filters, ["login"])
print users

However, this is not a project specific search and will not be very performant, just want to know what is the reason for gathering this data? Maybe we can find a better method if we know what the end result you are looking for is?

Hope that makes sense,


Thanks! We went another route for efficiency’s sake.