# add new custom field into lead table

**URL:** <https://forum.mautic.org/t/add-new-custom-field-into-lead-table/9302>\
**Category:** Product Support\
**Created:** [August 25, 2017, 3:29am UTC](https://forum.mautic.org/t/add-new-custom-field-into-lead-table/9302 "2017-08-25T03:29:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishal](https://avatars.discourse-cdn.com/v4/letter/v/49beb7/32.png) [@vishal](https://forum.mautic.org/u/vishal)\
**Post date:** [August 25, 2017, 3:29am UTC](https://forum.mautic.org/t/add-new-custom-field-into-lead-table/9302/1 "2017-08-25T03:29:58Z")

</div>

Hi,  
  
I want to add a new custom field (“age”) into leads table from my app bundle(plugin) programmatically.  
  
how can I add a new field into database leads table programmatically?

---

<div class="post-metadata">

**Author:** ![vishal](https://avatars.discourse-cdn.com/v4/letter/v/49beb7/32.png) [@vishal](https://forum.mautic.org/u/vishal)\
**Post date:** [August 25, 2017, 3:29am UTC](https://forum.mautic.org/t/add-new-custom-field-into-lead-table/9302/2 "2017-08-25T03:29:58Z")

</div>

Hi,  
I want to add a new custom field (“age”) into leads table from my app bundle(plugin) programmatically.  
how can I add a new field into database leads table programmatically?

---

<div class="post-metadata">

**Author:** ![robdex](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/robdex/32/1352_2.png) [@robdex](https://forum.mautic.org/u/robdex)\
**Post date:** [December 16, 2019, 11:23am UTC](https://forum.mautic.org/t/add-new-custom-field-into-lead-table/9302/3 "2019-12-16T11:23:42Z")

</div>

Hello @vishal, did you find a solution for this question?

Thank you.

---

<div class="post-metadata">

**Author:** ![alban](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alban/32/1959_2.png) [@alban](https://forum.mautic.org/u/alban)\
**Post date:** [December 17, 2019, 10:21pm UTC](https://forum.mautic.org/t/add-new-custom-field-into-lead-table/9302/4 "2019-12-17T22:21:02Z")

</div>

To create a new custom field programmatically it’s here : [https://developer.mautic.org/#create-field](https://developer.mautic.org/#create-field)

I assume what you want to do is to assign an age’s value to your leads programmatically, not “define” the custom field itself.

Well, once the field is created you can also modify the age for a specific lead through the API by hitting the contact’s endpoint.  
The flow could be something like that:  
1 Get contact’s id from the email address ([https://developer.mautic.org/#list-contacts](https://developer.mautic.org/#list-contacts))  
2 With the id, edit contact custom fields by passing the key:value pair in the data array ([https://developer.mautic.org/#edit-contact](https://developer.mautic.org/#edit-contact))

---

<div class="post-metadata">

**Author:** ![robdex](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/robdex/32/1352_2.png) [@robdex](https://forum.mautic.org/u/robdex)\
**Post date:** [December 18, 2019, 8:44am UTC](https://forum.mautic.org/t/add-new-custom-field-into-lead-table/9302/5 "2019-12-18T08:44:30Z")

</div>

Thanks @alban.  
Finally I used API method like that you link here but I was searching for a method that create a new custom field for contact/company without calling the API from inside Mautic.  
I tried with `ORM\ClassMetadata $builder` and something like `$builder->createField('my_custom_field', 'text')->nullable()->build();` inside an helper but it doesn’t work.

Thanks anyway.

---

<div class="post-metadata">

**Author:** ![cesarzubillaga](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/cesarzubillaga/32/395_2.png) [@cesarzubillaga](https://forum.mautic.org/u/cesarzubillaga)\
**Post date:** [March 25, 2021, 9:26am UTC](https://forum.mautic.org/t/add-new-custom-field-into-lead-table/9302/6 "2021-03-25T09:26:49Z")

</div>

Hi

To add a new Field you can do it like this:

```
    $field = new LeadField();
    /** @var FieldModel $model */
    $model = $this->getContainer()->get('mautic.model.factory')->getModel('lead.field');
    $field
        ->setLabel('Yout Label')
        ->setAlias('your alias')
        ->setDefaultValue(false)
        ->setType('boolean');
    $model->saveEntity($field);
```
