# How to automatically set group and primary\_group for the user?

**URL:** https://meta.discourse.org/t/how-to-automatically-set-group-and-primary-group-for-the-user/151600
**Category:** Feature
**Created:** [May 15, 2020, 12:43pm UTC](https://meta.discourse.org/t/how-to-automatically-set-group-and-primary-group-for-the-user/151600 "2020-05-15T12:43:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Konrad\_Sopala](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/konrad_sopala/32/167014_2.png) [@Konrad\_Sopala](https://meta.discourse.org/u/Konrad_Sopala)
#### Post date: [May 15, 2020, 12:43pm UTC](https://meta.discourse.org/t/how-to-automatically-set-group-and-primary-group-for-the-user/151600/1 "2020-05-15T12:43:21Z")

</div>

Hey there Folks!

The usecase is pretty straightfoward. We want folks with our company domain to be automatically added to my\_company\_employees group and set it as a primary group for them while anyone else with different email domain to be added to external\_users group and have it set as a primary group.

 ![Screenshot 2020-05-15 at 14.39.35](https://global.discourse-cdn.com/meta/original/3X/6/e/6e3f5a9b61feefcae2ec93c8a800e3b279e0defd.png)

Right now it’s only possible to match people with specific email domains. What about setting it the way that if somebody doesn’t match the email domain pattern, they get automatically added to certain group?

Thanks for help!

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 15, 2020, 12:48pm UTC](https://meta.discourse.org/t/how-to-automatically-set-group-and-primary-group-for-the-user/151600/2 "2020-05-15T12:48:16Z")

</div>

I think you’d need a plugin.

But what problem is the not-an-employee group going to solve?

---

<div class="post-metadata">

### Author: ![Konrad\_Sopala](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/konrad_sopala/32/167014_2.png) [@Konrad\_Sopala](https://meta.discourse.org/u/Konrad_Sopala)
#### Post date: [May 19, 2020, 11:54am UTC](https://meta.discourse.org/t/how-to-automatically-set-group-and-primary-group-for-the-user/151600/3 "2020-05-19T11:54:02Z")

</div>

No longer a valid question but thanks for making me thing. I simply used `primary_group_id is NULL`.  
Thanks for help Jay!
