# Import "set" field type not working

**URL:** https://discourse.getcockpit.com/t/import-set-field-type-not-working/2052
**Category:** Support
**Created:** [August 26, 2021, 3:17pm UTC](https://discourse.getcockpit.com/t/import-set-field-type-not-working/2052 "2021-08-26T15:17:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![prisonerjohn](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/prisonerjohn/32/667_2.png) [@prisonerjohn](https://discourse.getcockpit.com/u/prisonerjohn)
#### Post date: [August 26, 2021, 3:17pm UTC](https://discourse.getcockpit.com/t/import-set-field-type-not-working/2052/1 "2021-08-26T15:17:47Z")

</div>

Hello, I have a large data set (~4000 entries) that I want to import into my Cockpit CMS using the JSON importing tool, and it is mostly working correctly except for “set” type fields, which do not seem to be pulling in the data. All the other fields are importing correctly.

My set fields have a configuration like the following:

```auto
{
  "fields": [
    {
      "name": "tag",
      "label": "Tag",
      "type": "text"
    },
    {
      "name": "description",
      "label": "Description",
      "type": "text"
    }
  ],
  "display": null,
  "limit": null
}

```

and the corresponding JSON object looks like this:

```auto
    "_1xx": {
      "tag": "150",
      "description": "$aAbenaki"
    },

```

The really odd thing is that if I fill in an entry manually on the CMS then export the collection as JSON, it looks identical to the JSON file I am trying to import. Here is a short sample, the fields in question are `_053` and `_1xx`.

The JSON I am trying to import:

```auto
[
  {
    "_ldr": "00398cz a2200145n 4500",
    "_001": "sh00006813",
    "_003": "DLC",
    "_005": "20090114131843.0",
    "_008": "000523||\\dnannbbba\\\\\\\\\\\\\\\\\\\\|n\\ann\\\\\\\\\\\\",
    "_010": "$ash 00006813",
    "_040": "$aDLC$beng$cDLC$dDLC",
    "_053": {
      "indicator_2": "\\",
      "description": "$aE99.A13"
    },
    "_1xx": {
      "tag": "180",
      "description": "$xIndigenous influences"
    },
    "_revised_heading": "Indigenous influences",
    "_4xx": [
      {
        "value": {
          "tag": "480",
          "indicator_1": "\\",
          "indicator_2": "\\",
          "description": "$xIndian influences"
        }
      }
    ],
    "_667_68x": [
      {
        "value": {
          "tag": "680",
          "indicator_1": "\\",
          "indicator_2": "\\",
          "description": "$iUse as a topical subdivision under individual literatures."
        }
      }
    ]
  }
]

```

And the collection JSON exported out of Cockpit:

```auto
[
    {
        "_ldr": "00398cz a2200145n 4500",
        "_revised_heading": "Indigenous influences",
        "_001": "sh00006813",
        "_003": "DLC",
        "_005": "20090114131843.0",
        "_008": "000523||\\dnannbbba\\\\\\\\\\\\\\\\\\\\|n\\ann\\\\\\\\\\\\",
        "_010": "$ash 00006813",
        "_040": "$aDLC$beng$cDLC$dDLC",
        "_073": null,
        "_1xx": {
            "tag": null,
            "description": null
        },
        "_4xx": [
            {
                "value": {
                    "tag": "480",
                    "indicator_1": "\\",
                    "indicator_2": "\\",
                    "description": "$xIndian influences"
                }
            }
        ],
        "_667_68x": [
            {
                "value": {
                    "tag": "680",
                    "indicator_1": "\\",
                    "indicator_2": "\\",
                    "description": "$iUse as a topical subdivision under individual literatures."
                }
            }
        ],
        "_by": "611f04e27f4a970d7f1d2951",
        "_mby": "611f04e27f4a970d7f1d2951",
        "_modified": 1629990921,
        "_053": {
            "indicator_2": null,
            "description": null
        },
        "_260": null,
        "_360": null,
        "_5xx": null,
        "_8xx": null,
        "_9xx": null,
        "_created": 1629990386,
        "_id": "6127adf2971e2c3d5f0d5921"
    }
]

```

Does anyone have any ideas into what could be going wrong? Is this a bug? Is there another way I can update those fields?

Thank you!

---

<div class="post-metadata">

### Author: ![abernh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/abernh/32/859_2.png) [@abernh](https://discourse.getcockpit.com/u/abernh)
#### Post date: [August 27, 2021, 8:39am UTC](https://discourse.getcockpit.com/t/import-set-field-type-not-working/2052/2 "2021-08-27T08:39:28Z")

</div>

I tried to reproduce your problem and yes, there seems to be a bug.

My steps

- created a simple collection with
  - `text` field
  - `asset` field
  - `set` field with `text` sub-fields

- entered some data into all (sub)fields
- saved
- exported  
The values showed up correctly in my export (not `null` like in yours)
- imported  
 → `asset` and `set` field were set to `null`

The problem starts on `doImport` when the parsed data is once more re-parsed to be then sent to `Import::execute`.  
For any fields that have an object instead of a simple text value it expects a `type` key that is then compared with the `field.type`.  
And that `type` key is completely missing.

> <https://github.com/agentejo/cockpit/blob/568b0124352f6d27df359e8c19a70d2dd1961e87/modules/Collections/views/import/collection.php#L331>

I’d expect this `type` key to be set some time after the field-mapping is confirmed.

So yes, this is a bug.

### Possible workaround (\*not tested)

To get your import “working” you could disable lines `330,331` in the cockpit source and it might import fine.

_Note_: I filed a bug report [[bug] Importing "object-structured" fields sets fields to `null` · Issue #1464 · agentejo/cockpit · GitHub](https://github.com/agentejo/cockpit/issues/1464)

---

<div class="post-metadata">

### Author: ![prisonerjohn](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/prisonerjohn/32/667_2.png) [@prisonerjohn](https://discourse.getcockpit.com/u/prisonerjohn)
#### Post date: [August 27, 2021, 2:52pm UTC](https://discourse.getcockpit.com/t/import-set-field-type-not-working/2052/3 "2021-08-27T14:52:44Z")

</div>

Ok thanks for checking it! I just subscribed to the issue to follow progress.  
FWIW, I was able to push my data using the API `/api/collections/save/` so I’m using that for now.

---

<div class="post-metadata">

### Author: ![abernh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/abernh/32/859_2.png) [@abernh](https://discourse.getcockpit.com/u/abernh)
#### Post date: [August 27, 2021, 2:54pm UTC](https://discourse.getcockpit.com/t/import-set-field-type-not-working/2052/4 "2021-08-27T14:54:23Z")

</div>

Yes, true. This is only an issue when importing via the UI.  
Importing via the CLI or API is not affected by this.
