Skip to content

make ContactIsInGroup work for dynamic groups as well

When I was first asked to create the ”Contact is in Group” condition it had been assumed that this would work for dynamic groups as well. It turns out that the condition I modelled this on (Contact has Tag) uses the API in a way that, when adapted to groups, did not do that. I did not find a simple way to get all the groups that a contact belongs to if the task is to include the contact’s dynamic groups.

I therefore had to use a different approach, and this one seems to be simple and efficient: I am using a single API 4 call to ask for all contacts that a) have the required groups (using the OR or AND conjunction between these groups, depending on the choice of operator) and that b) have the ID of the given contact. This works with dynamic groups too. The result is either empty or contains just the given contact, so I can check whether it is non-empty to get the condition result. (The “has none of groups” operator is implemented by negating “has all groups”.)

Merge request reports

Loading