# New agent forest - define models enum values

**URL:** https://community.forestadmin.com/t/new-agent-forest-define-models-enum-values/7761
**Category:** Help me!
**Tags:** howtos
**Created:** [January 17, 2025, 1:44pm UTC](https://community.forestadmin.com/t/new-agent-forest-define-models-enum-values/7761 "2025-01-17T13:44:55Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Adel\_de\_Clevermate](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/adel_de_clevermate/32/4608_2.png) [@Adel\_de\_Clevermate](https://community.forestadmin.com/u/Adel_de_Clevermate)
#### Post date: [January 17, 2025, 1:44pm UTC](https://community.forestadmin.com/t/new-agent-forest-define-models-enum-values/7761/1 "2025-01-17T13:44:55Z")

</div>

## Feature(s) impacted

![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/0/06c7e10cf0b4ea86239c649813f3882098cb2020.png)

in order to change a gender for EXAMPLE i want to show a dropdown list instead of text input.  
I would like to do this on code not on the UI.

## Context

migration from forest v9 to the new nodejs agent.  
in the old forest version I was editing in the models files but in the new forest agent I dont find a way to do the same.

- Project name: Clevermate v2
- Agent technology: (nodejs,
- Agent (forest package) name & version: …
- Database type: postges

---

<div class="post-metadata">

### Author: ![anon7311026](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@anon7311026](https://community.forestadmin.com/u/anon7311026)
#### Post date: [January 17, 2025, 1:47pm UTC](https://community.forestadmin.com/t/new-agent-forest-define-models-enum-values/7761/2 "2025-01-17T13:47:24Z")

</div>

Hello @Adel_de_Clevermate,

The agent should pick up what is defined in your ORM models or database and use that in the schema.  
Do you have an enum in either of those ?  
Thanks 🙏

---

<div class="post-metadata">

### Author: ![Adel\_de\_Clevermate](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/adel_de_clevermate/32/4608_2.png) [@Adel\_de\_Clevermate](https://community.forestadmin.com/u/Adel_de_Clevermate)
#### Post date: [January 17, 2025, 2:05pm UTC](https://community.forestadmin.com/t/new-agent-forest-define-models-enum-values/7761/3 "2025-01-17T14:05:18Z")

</div>

Hi @anon7311026

No, I dont have. the field on databse is of type varchar, I dont get where I can see the ORM models.

---

<div class="post-metadata">

### Author: ![anon7311026](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@anon7311026](https://community.forestadmin.com/u/anon7311026)
#### Post date: [January 17, 2025, 2:27pm UTC](https://community.forestadmin.com/t/new-agent-forest-define-models-enum-values/7761/4 "2025-01-17T14:27:17Z")

</div>

Ok,

What you can do is use an `addField` customization on the collection. Something like that should work for you:

```javascript
    UserCollection.addField('UserGenderWithEnum', {
      columnType: 'Enum',
      enumValues: ['M', 'F', 'O'],
      dependencies: ['UserGender'],
      getValues(records) {
        return records.map(record => {
          switch (record.UserGender) {
            case 'M':
            case 'Male':
              return 'M';

            case 'F':
            case 'Female':
              return 'F';

            case 'O':
            case 'Other':
              return 'O';

            default:
              return null;
          }
        });
      },
    })
    .removeField('UserGender')
    .replaceFieldWriting('UserGenderWithEnum', async value => {
      return { UserGender: value };
    });

```

> **[Add fields | Node.js Developer Guide](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/fields/computed)**

> **[Override writing behavior | Node.js Developer Guide](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/fields/write#changing-other-fields-in-the-same-record)**

Please note that you may have to enable writing for the field in the UI, as computed fields are readonly by default.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/8/8aaccf687ec9d413e66c2f39504fe612f58c9f2f.png)

It will effectively replace the `UserGender` field with `UserGenderWithEnum` in your forest schema  
Please let me know if this is ok for your use case 🙏

---

<div class="post-metadata">

### Author: ![Adel\_de\_Clevermate](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/adel_de_clevermate/32/4608_2.png) [@Adel\_de\_Clevermate](https://community.forestadmin.com/u/Adel_de_Clevermate)
#### Post date: [January 17, 2025, 2:57pm UTC](https://community.forestadmin.com/t/new-agent-forest-define-models-enum-values/7761/5 "2025-01-17T14:57:16Z")

</div>

Thank you @anon7311026

This looks good to resolve the issue. ✅  
Unless there is other simpler way with less code lines, since we have many more fields like this and on many collections.

Thank you 🙏

---

<div class="post-metadata">

### Author: ![anon7311026](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@anon7311026](https://community.forestadmin.com/u/anon7311026)
#### Post date: [January 20, 2025, 8:18am UTC](https://community.forestadmin.com/t/new-agent-forest-define-models-enum-values/7761/6 "2025-01-20T08:18:19Z")

</div>

You may want to look into factorizing your enum declarations using plugins.  
Here is very similar example in our plugins repo:

> <https://github.com/ForestAdmin/forestadmin-experimental/blob/main/packages/plugin-define-enum/README.md>

> <https://github.com/ForestAdmin/forestadmin-experimental/blob/main/packages/plugin-define-enum/src/index.ts>

You can take inspiration from there to limit boilerplate in your customization code.  
I hope this helps
