Skip to main content

How to automate group management

Use automated rules to keep group memberships in sync with People Segments, or to dynamically create groups based on user attributes. Covers both group-management actions.

Written by Michael Wallace

Scenario

As an admin or site owner, you want to automate group memberships — either to keep a specific group in sync with a segment, or to manage a set of groups whose names and members come from user attributes.

Solution

  1. Make sure a People Segment exists for the people the rule should affect.
    For more on segments, see How to use dashboard segments.

  2. Create a new automated rule.
    For the full procedure, see How to create an automated rule.

  3. Under Action, choose either Assign to a group or Assign to group(s) by template.

  4. Configure the action's field:

    • For Assign to a group, select the Group to sync with the segment. You can also create a new group from the Create a new group link below the dropdown.

    • For Assign to group(s) by template, enter a Group name template. Optionally, set a Group name delimiter to split the rendered template into multiple group names. See How Assign to group(s) by template works in the Go deeper section.

  5. Click Publish.

The rule runs on its scheduled cadence, evaluating the segment and updating group memberships accordingly.

Go deeper

How Assign to a group syncs membership

The Assign to a group action keeps a single group's membership in sync with the segment:

  • People who match the segment and are not already in the group are added.

  • People who are in the group but no longer match the segment are removed.

A rule can only target one group, so to automate multiple groups with Assign to a group, create one rule per group.

Because the action syncs membership both ways, manual additions to a rule-managed group are removed on the next run if the manually-added person does not match the segment. To preserve manually-managed memberships, use a separate group for manual additions.

How Assign to group(s) by template works

The Assign to group(s) by template action evaluates a Group name template for each person in the segment. The person is added to the group whose name the template evaluates to. Like Assign to a group, the action then keeps each managed group in sync with the segment — people who no longer evaluate to a given group name are removed from it. If no group with the resulting name exists, it is created automatically.

The template can be a fixed string (every person in the segment goes to the same group, for example People Managers) or a Django template that references the person's attributes. Available attributes:

  • {{ title }} — the user's title

  • {{ department }} — the user's department

  • {{ location }} — the user's location

  • {{ manager.name }} — the user's manager's name

  • {{ manager.email }} — the user's manager's email

  • {{ custom.* }} — any custom attribute from People Integration, for example {{ custom.employee_type }}

Django template tags are supported, including conditionals like {% if … %}{% endif %}.

Leading and trailing whitespace in the evaluated group name is trimmed automatically. If the template evaluates to an empty string for a given user, that user is skipped.

Example: one group per office

If users have a custom attribute office with values like SF, NY, or Boston, this template:

{{ custom.office }} Office

generates and maintains SF Office, NY Office, and Boston Office. When a new office value appears (for example, Boulder), the rule creates the Boulder Office group automatically and adds matching users — no rule edits required.

Example: one group per manager's direct reports

This template:

{% if manager %}{{ manager.email }}'s directs{% endif %}

generates a group named <manager email>'s directs for each manager, populated with that manager's direct reports. The {% if manager %} conditional skips users who do not have a manager.

Adding people to multiple groups with a delimiter

The action's Group name delimiter field lets a single template produce multiple groups. When set, the rendered template is split on the delimiter, and the person is added to each resulting group.

The most common use case is a multi-valued custom attribute. If users have a custom attribute groups containing values like engineering, on-call, sre, this combination:

  • Group name template: {{ custom.groups }}

  • Group name delimiter: ,

adds each user to all three groups: engineering, on-call, and sre. Whitespace on either side of each delimited value is stripped automatically.

If the Group name delimiter is left blank, the template is treated as a single group name.

Delete stale groups

When a rule using Assign to group(s) by template stops producing a given group name — for example, the last user with office = Boulder moves elsewhere — the group still exists, just empty. To clean these up automatically, enable the Delete stale groups setting in System Settings. With this setting on, groups that no longer have any matching users are removed after the next evaluation.

Combining group rules with other rules

Group membership often drives other automation. Rules run sequentially top-to-bottom, so place group-management rules ahead of any rules whose segments filter on those groups. For details on ordering and cross-rule dependencies, see Reference: How automated rules run.

Did this answer your question?