Contentful logo

Contentful Community

Simple Migration - Help Needed

Hey all, first time poster, please forgive me if I get some of the terminology wrong :slight_smile:

We have a data model that looks like this (forgive some of the field names, I changed their actual names vs. what we’re using):

embeddedObj : Object (contains fields: uuid, title)
someOtherField: Short text
uuid: Short text

I have a migration I’m attempting to set up, but I keep getting that the field is undefined. Essentially we have added a new field uuid at the top level of our model. We would like to copy the value of the UUID in the embedded object and update the uuid field at the top level. Here’s what the migration script looks like:

   module.exports = function (migration) {
        migration.transformEntries({
                contentType: 'myContentType',
                from: ['embeddedObj'],
                to: ['uuid'],
                transformEntryForLocale: function (fromFields, currentLocale) {
                        const obj = fromFields.embeddedObj[currentLocale];
                        return { uuid: obj.uuid };
                }   
        }); 
}

This is the error I’m getting:

TypeError: Cannot read property ‘en-US’ of undefined

I gather that’s because fromFields.embeddedObj is undefined. I’m not entirely sure what I’m doing wrong. Can anyone offer any thoughts on what I can try? FWIW I also tried copying from someOtherField to uuid (at the top level) and was getting the same error.

Thanks in advance!

Hi @will.taylor, when you say embeddedObj, do you mean a Linked Entry? Or might be somehow an entry included inside a Rich Text field?