How do I modify content createdTime (and possibly modifiedTime)?

I’m importing content from a different system. Importing works fine, but I cannot change the content createdTime. From another thread it’s implied that it should be possible?

(I also want to change the modifiedTime, however I see that modifying modifiedTime is somewhat semantically odd, and might be immediately overridden by the system.)

Should it be possible? Dumping/exporting the data from XP, and modifying the files before importing them again seems like a wrong approach…

This is my code. I’ve tried a gazillion different timestamp and date formats, with no luck. Also, I get no error messages. The content for these two fields simply doesn’t change. Hopefully I’m just overseeing something obvious here.

if (result) {
    var updatedPost = contentLib.modify({
        key: result._id,
        editor: function (c) {
            c.createdTime = myImportedData.date_gmt;
            c.modifiedTime = myImportedData.modified_gmt;
            c.data.whatever = 'This is changed just fine';
            return c;
        }
    });
    if (!updatedPost) {
        log.error('Unable to update ' + result._path + ' with new dates');
    }
}

Hello sir.

The createdTime/modifiedTime properties are properties handled automatically in the content-domain. They are supposed to work as timestamp-like properties, and not manipulated in the content-api.

If you need to do this, you should work in the node-api where you can do whatever you want with the data.
If you want to import this as content, you could do it in two operations; first create the content through the content-api, then do an immediate modify on the same content through the node-api:

http://repo.enonic.com/public/com/enonic/xp/docs/6.10.1/docs-6.10.1-libdoc.zip!/module-node-RepoConnection.html#modify

// Editor to call for node.
function setCreatedTime(node) {
    node.createdTime = <something>;
    return node;
}

// Modify node by id
var result = repo.modify({
    key: <my content id>,
    editor: setCreatedTime
});
3 Likes

This actually makes a ton of sense. Thank you very much!!

1 Like