# Re-using the same field in several custom modules

**URL:** <https://community.hubspot.com/t/re-using-the-same-field-in-several-custom-modules/72526>\
**Category:** CMS Development\
**Created:** [January 10, 2023, 11:10am UTC](https://community.hubspot.com/t/re-using-the-same-field-in-several-custom-modules/72526 "2023-01-10T11:10:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DM2](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dm2/32/39641_2.png) [@DM2](https://community.hubspot.com/u/DM2)\
**Post date:** [January 10, 2023, 11:10am UTC](https://community.hubspot.com/t/re-using-the-same-field-in-several-custom-modules/72526/1 "2023-01-10T11:10:57Z")

</div>

Hi

I have a field I use in a custom module that applies a style to a button - it’s a “Choice” field with many different options.

I want to use that button in lots of other different custom modules but I don’t want to have to keep on repeating the entry of all the options when creating the field.

Is there a away of holding that field “centrally” and then dropping it in to custom modules - a global field if you like? I’m assuming we can’t have modules within modules still…

Thanks for any advice!

Dan

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [January 10, 2023, 1:42pm UTC](https://community.hubspot.com/t/re-using-the-same-field-in-several-custom-modules/72526/2 "2023-01-10T13:42:59Z")

</div>

Hi @DM2

Unfortunately, this isn’t possible since you can’t nest a custom module inside another custom module and, there’s no real good way to create a global dictionary that would be available to all of your custom modules. The timing of the loading of the custom modules vs. the timing of setting the dictionary values would be hit or miss.

Hope this will helpful !

Gaurav Rajput

---

<div class="post-metadata">

**Author:** ![DM2](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dm2/32/39641_2.png) [@DM2](https://community.hubspot.com/u/DM2)\
**Post date:** [January 11, 2023, 8:50am UTC](https://community.hubspot.com/t/re-using-the-same-field-in-several-custom-modules/72526/3 "2023-01-11T08:50:20Z")

</div>

thanks for your response @GRajput

I wonder if anyone else has come up against this and found a suitable workround?

---

<div class="post-metadata">

**Author:** ![EdCupaioli](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/edcupaioli/32/103251_2.png) [@EdCupaioli](https://community.hubspot.com/u/EdCupaioli)\
**Post date:** [May 21, 2024, 6:01pm UTC](https://community.hubspot.com/t/re-using-the-same-field-in-several-custom-modules/72526/4 "2024-05-21T18:01:40Z")

</div>

This is very advanced javascript and their method isn’t clearly documented so I do not blame you. In cloudcannon, I would just add my field configs to a global config file to be inherited by all of my module but the root fields.json is just designated for the theme (eg adding colors, fonts, and meta). Here’s what I did and I would hope that @alyssamwilie has some additional insight to these [rest of the owl](https://res.cloudinary.com/practicaldev/image/fetch/s--OCc2jm4N--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://i.kym-cdn.com/photos/images/newsfeed/000/572/078/d6d.jpg) docs hubspot has:  
**Requirements**

As a developer, I want to create a global field group that I can reference across several modules in the fields.json file of each module.

**Steps to Recreate**

1. I created a subdirectory in my theme folder named global fields (my-theme/global-fields)
2. I added a fields.js file to the root of my global-fields folder and added the code from the [Common fields](https://developers.hubspot.com/docs/cms/building-blocks/modules/write-fields-using-javascript#common-fields) docs.
3. I cd into my theme directory (cd my-theme) and ran the following command:

`hs cms convert-fields --src=global-fields/fields.js​`

**What I Expected**

I expected to be able to refence the fields.json generated by the hs cms convert-fields command in mutliple modules.

**What Happened**

No docs on how to systematically set common fields for modules. Just generating an output file per module which seems inefficient.

A fields.output.json was generated. It appeared to be just like the fields.json I have in all of my modules. However, there is no clear method of importing that fields.output.json outside of copying the json and adding it to each of my modules. I’m also curious as to why I have to write a separate javascript in order to generate JSON that I can easily write myself without the complexities of module.exports.

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [January 15, 2023, 6:26am UTC](https://community.hubspot.com/t/re-using-the-same-field-in-several-custom-modules/72526/5 "2023-01-15T06:26:11Z")

</div>

Don’t know if you build locally using the HubSpot CLI but HubSpot actually has public beta out right now for writing fields.json using Javascript that includes the ability to create a fields.js of common fields that can be imported and used across multiple modules:

> **[Write module and theme fields using JavaScript - HubSpot docs](https://developers.hubspot.com/docs/cms/start-building/building-blocks/fields/write-fields-using-javascript)**
>
> Learn how to write a module's fields.json file using JavaScript.

---

<div class="post-metadata">

**Author:** ![DM2](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dm2/32/39641_2.png) [@DM2](https://community.hubspot.com/u/DM2)\
**Post date:** [January 16, 2023, 8:59am UTC](https://community.hubspot.com/t/re-using-the-same-field-in-several-custom-modules/72526/6 "2023-01-16T08:59:05Z")

</div>

Thanks @alyssamwilie I will check that out. I do the use the HS CLI but don’t write js from scratch so it might be a bit beyond me.
