# \--convertFields doesn't upload 2 fields

**URL:** <https://community.hubspot.com/t/convertfields-doesnt-upload-2-fields/86467>\
**Category:** CMS Development\
**Tags:** local-development, javascript\
**Created:** [July 31, 2023, 2:15pm UTC](https://community.hubspot.com/t/convertfields-doesnt-upload-2-fields/86467 "2023-07-31T14:15:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![keyword](https://avatars.discourse-cdn.com/v4/letter/k/ebca7d/32.png) [@keyword](https://community.hubspot.com/u/keyword)\
**Post date:** [July 31, 2023, 2:15pm UTC](https://community.hubspot.com/t/convertfields-doesnt-upload-2-fields/86467/1 "2023-07-31T14:15:29Z")

</div>

Hi,  
The question is related to a new --convertFields feature. I have created a module called “buttons” with fields.mjs file which exports this function:

```lia-code-sample
function buttons(maxLimit = 3, id ="buttons", controlling_field_path = "buttons.button_icon") {
 const button = {
 "id" : id,
 "name" : id,
 "display_width" : null,
 "label" : id,
 "required" : false,
 "locked" : false,
 "occurrence" : {
 "min" : null,
 "max" : maxLimit,
 "sorting_label_field" : `${id}.button_text`,
 "default" : 1
 },
 "children" : [ {
 "id" : `${id}.button_text`,
 "name" : "button_text",
 "display_width" : null,
 "label" : "Button Text",
 "required" : false,
 "locked" : false,
 "validation_regex" : "",
 "allow_new_line" : false,
 "show_emoji_picker" : false,
 "type" : "text",
 "default" : "Button example"
 }, {
 "id" : `${id}.button_link`,
 "name" : "button_link",
 "display_width" : null,
 "label" : "Button Link",
 "required" : false,
 "locked" : false,
 "supported_types" : ["EXTERNAL", "CONTENT", "FILE", "EMAIL_ADDRESS", "BLOG"],
 "show_advanced_rel_options" : false,
 "type" : "link",
 "default" : {
 "url" : {
 "content_id" : null,
 "type" : "CONTENT",
 "href" : ""
 },
 "open_in_new_tab" : false,
 "no_follow" : false
 }
 }, {
 "id" : "button_style",
 "name" : "button_style",
 "display_width" : null,
 "label" : "Button Style",
 "required" : false,
 "locked" : false,
 "display" : "select",
 "choices" : [[ "button--primary", "Primary"], ["button--secondary", "Secondary"], ["button__link", "Text button"] ],
 "multiple" : false,
 "reordering_enabled" : true,
 "preset" : null,
 "type" : "choice",
 "default" : "button--primary"
 }, {
 "id" : "button_icon",
 "name" : "button_icon",
 "display_width" : null,
 "label" : "Button icon",
 "required" : false,
 "locked" : false,
 "display" : "checkbox",
 "type" : "boolean",
 "default" : false
 }, {
 "id" : "icon_type",
 "name" : "icon_type",
 "display_width" : null,
 "label" : "Icon type",
 "required" : false,
 "locked" : false,
 "visibility" : {
 "controlling_field" : null,
 "controlling_field_path" : controlling_field_path,
 "controlling_value_regex" : "true",
 "property" : null,
 "operator" : "EQUAL",
 "access" : null
 },
 "display" : "select",
 "choices" : [[ "arrow", "Arrow"], ["check", "Check mark"] ],
 "multiple" : false,
 "reordering_enabled" : true,
 "preset" : null,
 "type" : "choice",
 "default" : "arrow"
 } ],
 "tab" : "CONTENT",
 "expanded" : false,
 "type" : "group",
 "default" : [ {
 "button_text" : "Button example",
 "button_link" : {
 "url" : {
 "content_id" : null,
 "type" : "CONTENT",
 "href" : ""
 },
 "open_in_new_tab" : false,
 "no_follow" : false
 },
 "button_style" : "button--primary",
 "button_icon" : false,
 "icon_type" : "arrow"
 } ]
 } 
 return [button]
}

export default buttons;

```

I want to inject these buttons fields into another module in two different group fields like so:

```lia-code-sample
import button from '../elements/button.module/fields.mjs'
import heading from '../elements/heading.module/fields.mjs'

function contentCards() {
 const leftButton = button("2", "buttons2", "left_card.buttons2.button_icon")[0]
 const rightButton = button("2", "buttons2", "right_card.buttons2.button_icon")[0]
		const leftCard = {
 "id" : "27bdf84b-1d52-1540-a9e1-eaaea502892a",
 "name" : "left_card",
 "display_width" : null,
 "label" : "Left card",
 "required" : false,
 "locked" : false,
 "children" : [ {
 "id" : "8b1b1c7d-fd3c-eb98-8e63-a2705d4055b4",
 "name" : "title_1",
 "display_width" : null,
 "label" : "Title-1",
 "required" : false,
 "locked" : false,
 "validation_regex" : "",
 "allow_new_line" : false,
 "show_emoji_picker" : false,
 "type" : "text",
 "default" : "Apex title"
 },
 {
 "id" : "bef61feb-53e1-41fd-7175-c0ecd6362530",
 "name" : "paragraph_1",
 "display_width" : null,
 "label" : "Paragraph-1",
 "required" : false,
 "locked" : false,
 "validation_regex" : "",
 "allow_new_line" : false,
 "show_emoji_picker" : false,
 "type" : "text",
 "default" : "Lacinia nam sed purus tempor id nunc vulputate. Sapien lorem integer eget quis suspendisse nulla. Ultricies scelerisque et pulvinar **bleep** at mauris."
 }, {
 "id" : "2630f0c6-9cc2-a5df-e8e0-6c8781bba212",
 "name" : "image_1",
 "display_width" : null,
 "label" : "Image-1",
 "required" : false,
 "locked" : false,
 "responsive" : true,
 "resizable" : true,
 "show_loading" : false,
 "type" : "image",
 "default" : {
 "size_type" : "auto",
 "src" : "https://26812157.fs1.hubspotusercontent-eu1.net/hubfs/26812157/test-folder/Apex_brand_lhd_RGB%201.png",
 "alt" : "Apex_brand_lhd_RGB 1",
 "loading" : "lazy",
 "width" : 933,
 "height" : 829,
 "max_width" : 933,
 "max_height" : 829
 }
 }, leftButton ],
 "tab" : "CONTENT",
 "expanded" : false,
 "type" : "group",
 "default" : {
 "title_1" : "Apex title",
 "paragraph_1" : "Lacinia nam sed purus tempor id nunc vulputate. Sapien lorem integer eget quis suspendisse nulla. Ultricies scelerisque et pulvinar **bleep** at mauris.",
 "image_1" : {
 "size_type" : "auto",
 "src" : "https://26812157.fs1.hubspotusercontent-eu1.net/hubfs/26812157/test-folder/Apex_brand_lhd_RGB%201.png",
 "alt" : "Apex_brand_lhd_RGB 1",
 "loading" : "lazy",
 "width" : 933,
 "height" : 829,
 "max_width" : 933,
 "max_height" : 829
 }
 }
 }
 const rightCard = {
 "id" : "17c0ef67-6aa8-6fe0-3df9-00f8033d1f96",
 "name" : "right_card",
 "display_width" : null,
 "label" : "Right card",
 "required" : false,
 "locked" : false,
 "children" : [ {
 "id" : "791e25f4-3152-925c-94d6-d3dec3372f51",
 "name" : "title_2",
 "display_width" : null,
 "label" : "Title-2",
 "required" : false,
 "locked" : false,
 "validation_regex" : "",
 "allow_new_line" : false,
 "show_emoji_picker" : false,
 "type" : "text",
 "default" : "Apex title"
 }, {
 "id" : "fdc55d4e-2a5c-9a16-acb9-5176f5e7794f",
 "name" : "paragraph_2",
 "display_width" : null,
 "label" : "Paragraph-2",
 "required" : false,
 "locked" : true,
 "validation_regex" : "",
 "allow_new_line" : false,
 "show_emoji_picker" : false,
 "type" : "text",
 "default" : "Lacinia nam sed purus tempor id nunc vulputate. Sapien lorem integer eget quis suspendisse nulla. Ultricies scelerisque et pulvinar **bleep** at mauris."
 }, {
 "id" : "e581424a-83c2-5cb1-362f-e8ba75603ff1",
 "name" : "image_2",
 "display_width" : null,
 "label" : "Image-2",
 "required" : false,
 "locked" : false,
 "responsive" : true,
 "resizable" : true,
 "show_loading" : false,
 "type" : "image",
 "default" : {
 "size_type" : "auto",
 "src" : "https://26812157.fs1.hubspotusercontent-eu1.net/hubfs/26812157/test-folder/Apex_brand_lhd_RGB%201.png",
 "alt" : "Apex_brand_lhd_RGB 1",
 "loading" : "lazy",
 "width" : 933,
 "height" : 829,
 "max_width" : 933,
 "max_height" : 829
 }
 }, rightButton ],
 "tab" : "CONTENT",
 "expanded" : false,
 "type" : "group",
 "default" : {
 "title_2" : "Apex title",
 "paragraph_2" : "Lacinia nam sed purus tempor id nunc vulputate. Sapien lorem integer eget quis suspendisse nulla. Ultricies scelerisque et pulvinar **bleep** at mauris.",
 "image_2" : {
 "size_type" : "auto",
 "src" : "https://26812157.fs1.hubspotusercontent-eu1.net/hubfs/26812157/test-folder/Apex_brand_lhd_RGB%201.png",
 "alt" : "Apex_brand_lhd_RGB 1",
 "loading" : "lazy",
 "width" : 933,
 "height" : 829,
 "max_width" : 933,
 "max_height" : 829
 }
 }
 }

		 return [heading('h1'), leftCard, rightCard]
}
export default contentCards;

```

For some reason it works only for one card. So if I add only leftButton to leftCard object, then it successfully uploads the fields and everything works, but it doesn’t work if I add both buttons to two cards at the same time.  
What am I doing wrong? I’m changing the id’s and controlling\_field\_path as they might be conflicting, but it always throws this error - [ERROR] Unrecognized token ‘import’: was expecting (JSON String, Number, Array, Object or token ‘null’, ‘true’ or ‘false’) (line:1, column:8)  
Would appreciate any help.

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [August 1, 2023, 9:18pm UTC](https://community.hubspot.com/t/convertfields-doesnt-upload-2-fields/86467/2 "2023-08-01T21:18:57Z")

</div>

Hey, @keyword 👋 Thanks for your question. And for providing your code examples. There’s a lot to unpack. My instinct is to start simple and see where that gets us.

From what I can tell, your button function is currently set up to return an array. And the button function in your contentCards function looks like you’re treating the return value as an object. This might be causing the error you’re experiencing.

Have you tried changing your button function to return an object instead of an array? Like this?

```lia-code-sample
function buttons(maxLimit = 3, id ="buttons", controlling_field_path = "buttons.button_icon") {
 //...your code
 return button;
}

export default buttons;

```

And use them like this?

```lia-code-sample
import button from '../elements/button.module/fields.mjs'
import heading from '../elements/heading.module/fields.mjs'

function contentCards() {
 const leftButton = button("2", "left_buttons", "left_card.left_buttons.button_icon");
 const rightButton = button("2", "right_buttons", "right_card.right_buttons.button_icon");

 // Rest of your code
}
export default contentCards;

```

Thanks again for sharing an interesting challenge with the community.

Talk soon! — Jaycee

---

<div class="post-metadata">

**Author:** ![keyword](https://avatars.discourse-cdn.com/v4/letter/k/ebca7d/32.png) [@keyword](https://community.hubspot.com/u/keyword)\
**Post date:** [August 2, 2023, 10:39am UTC](https://community.hubspot.com/t/convertfields-doesnt-upload-2-fields/86467/3 "2023-08-02T10:39:42Z")

</div>

Hi Jaycee,  
Thanks for your reply!  
Unfortunately, as I mentioned in the post, I created a button module and exported the function in fields.mjs, so this function should return an array of objects, otherwise it won’t be a valid fields export and will throw an error.  
Also, in contentCards() functon you can see that I target the object in the button funtion by setting the index to [0]:

`const rightButton = button("2", "buttons2", "right_card.buttons2.button_icon")[0]`

so it returns an object. Also, if I would just pass one button to the fields, it would work just fine, so button() being an array is not the issue here. The error occurs when I pass two buttons to two different objects (leftCard and rightCard) within one module.  
There should be some conflicting duplicate entries within button object that don’t let me upload the fields, but I can’t figure them out 😞
