# Automatically add users to groups based on custom field value

**URL:** https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858
**Category:** Feature
**Tags:** automation, completed, user-custom-fields
**Created:** [5월 6, 2018, 3:59오전 UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858 "2018-05-06T03:59:39Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![kstaikov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kstaikov/32/72615_2.png) [@kstaikov](https://meta.discourse.org/u/kstaikov)
#### Post date: [5월 6, 2018, 3:59오전 UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858/1 "2018-05-06T03:59:39Z")

</div>

When creating a group, we have the automatic membership setting based on a user’s email domain name. I would like to have this functionality based on the value of a custom field.

## Example Use Case

I have a condo community with a dropdown custom field signifying ownership status (Owner, Renter). I want to have all owners automatically in an owner group and to be able to message only all owners for certain messages.

## Caveats

This sounds straight forward for dropdown and confirmation custom fields, but I guess could get hairy for text fields. It would be fine to enable it only for dropdowns and confirmations, otherwise exact text match is fine for text fields.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [5월 9, 2018, 8:56오후 UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858/2 "2018-05-09T20:56:35Z")

</div>

Since these are user settable custom fields, you can just make the groups open membership and tell people to add / remove themselves via the /groups page.

---

<div class="post-metadata">

### Author: ![kstaikov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kstaikov/32/72615_2.png) [@kstaikov](https://meta.discourse.org/u/kstaikov)
#### Post date: [5월 11, 2018, 2:01오후 UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858/3 "2018-05-11T14:01:55Z")

</div>

Not realistic for my use case. Hard to get a bunch of random homeowners, some very old, to bother going around tinkering with their settings. It was hard enough getting them to just register once to get the emails, and it’s hard to even get them to pay attention and do stuff even when there are financial penalties.

---

<div class="post-metadata">

### Author: ![li-zi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/li-zi/32/161339_2.png) [@li-zi](https://meta.discourse.org/u/li-zi)
#### Post date: [11월 22, 2019, 1:51오전 UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858/4 "2019-11-22T01:51:06Z")

</div>

앞으로 이 글을 보게 될 분들을 위해 공유합니다. 저도 비슷한 사용 사례(서비스를 제공하는 사람 vs. 서비스를 찾는 사람)를 가지고 있었는데, 결국 웹훅과 Discourse API를 통해 구현했습니다.

구체적으로, 저는…

- 사용자 이벤트 발생 시 트리거되는 웹훅을 생성했습니다.
- 페이로드를 수신하기 위한 최소한의 Express.js 서버를 구현했습니다.
- `user_created` 이벤트에 대한 POST 라우트를 설정하여 사용자 정의 사용자 필드의 값을 확인한 후, Discourse API를 사용하여 사용자의 그룹을 그에 맞게 설정하도록 했습니다.

Discourse 외부에서 Discourse 내부의 요소를 수정하는 방식이라 다소 어색하게 느껴질 수 있지만, 포럼을 뒤져봐도 이에 대한 답을 찾지 못해 최선의 노력을 다했습니다. 이 글이 앞으로 누군가에게 도움이 되길 바라며, 더 나은 방법이 있다면 알려주시면 좋겠습니다.

---

<div class="post-metadata">

### Author: ![weallwegot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/weallwegot/32/124753_2.png) [@weallwegot](https://meta.discourse.org/u/weallwegot)
#### Post date: [4월 4, 2020, 11:32오후 UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858/5 "2020-04-04T23:32:28Z")

</div>

사용자 필드 드롭다운을 기준으로 사용자를 자동으로 세그먼트로 나누는, 이 기능과 매우 유사한 것을 구현해 보고 있습니다. 혹시 이 프로젝트를 오픈소스로 공개하신 적이 있으신가요?

제 사용 사례는 거의 동일하며, [여기서도 질문을 해 보았습니다](https://meta.discourse.org/t/user-card-directory/144479/14?u=weallwegot)

---

<div class="post-metadata">

### Author: ![weallwegot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/weallwegot/32/124753_2.png) [@weallwegot](https://meta.discourse.org/u/weallwegot)
#### Post date: [5월 20, 2020, 5:48오후 UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858/6 "2020-05-20T17:48:19Z")

</div>

> [@weallwegot](#):
>
> 커스텀 사용자 필드 드롭다운을 기반으로 사용자를 그룹으로 자동 세분화하기

@li-zi 님, 이미 해당 사례에 대해 해결하신 것 같지만, 또 다른 잠재적인 해결책은 [Custom Wizard 플러그인](https://meta.discourse.org/t/custom-wizard-plugin/73345)을 사용하는 것입니다.  
저는 이 플러그인을 사용하여 신규 사용자가 가입한 후 마법사(wizard)를 통해 정보를 입력하도록 유도합니다.  
마법사에는 드롭다운 옵션을 제공하는 필드가 몇 가지 있습니다.  
그런 다음 마법사가 제출된 후 완료할 두 가지 별도의 작업을 설정합니다:

- 드롭다운에서 선택한 마법사 필드로 사용자 프로필의 커스텀 필드를 업데이트하는 작업
- 마법사 필드 선택 사항에 따라 사용자를 특정 그룹에 추가하는 작업

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [8월 19, 2023, 7:52오후 UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858/7 "2023-08-19T19:52:35Z")

</div>

이 문제를 마무리하기 위해 말씀드리면, 이제 ‘커스텀 필드를 통해 사용자를 그룹에 추가’ 자동화 스크립트를 사용하여 이 작업을 수행할 수 있습니다. 🥳

이 방법을 자세히 알아보는 방법은 여기에서 확인하세요:

> [@사용자 정의 필드 자동화로 그룹에 사용자 추가하기](https://meta.discourse.org/t/add-user-to-group-through-custom-field-automation/275873):
>
> bookmark 이 가이드는 사용자가 가입 또는 프로필 업데이트 시 사용자 정의 필드를 선택한 내용에 따라 사용자를 자동으로 그룹에 추가하는 방법을 설명합니다. person_raising_hand 필요한 사용자 권한: 관리자 요약 필요한 그룹 생성 사용자 정의 필드 설정 사용자를 그룹에 추가하는 자동화 생성 설정 테스트 그룹 생성 먼저, 사용자가 자동으로 추가되길 원하는 그룹을 생성하세요: 사이트의 관리자 영역으로 이동합니다. 관리자 사이드바에서 '그룹’으로 이동하거나 /admin/groups를 방문합니다. 생성하려는 각 그룹에 대해 '새 그룹’을 클릭합니다. 자동화 스크립트가 이 값을 사용하므로 각 그룹에 '전체 이름(Full Name)'을 반드시 추가하세요. information_source 자동화 스크립트는 사용자의 사용자 정의 필드 값을 그룹의 \*\*전체 이름(Full Name)\*\*과 일치시킵니다. 각 그룹의 전…

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [8월 19, 2023, 7:52오후 UTC](https://meta.discourse.org/t/automatically-add-users-to-groups-based-on-custom-field-value/86858/8 "2023-08-19T19:52:38Z")

</div>


