Guys, I’m having some trouble while getting a content on different versions in the master branch.
My problem is that I need to get a published content on the current version and also get the same content on its previously published version to compare a specific field.
I changed the data.title
of a content on Content Studio and published it, when I get the last 100 versions of this content (contentLib.get({key: 'id', version: 'versionid'})
), all of them have the new value for data.title
. It looks like it’s not getting the content on the specified version.
The weird thing is that I went to Data toolbox and listed the versions of this same content and everything seems to work there.
TEST CODE THAT I’M USING:
exports.execute = function (event) {
Context.run(
{
repository: 'com.enonic.cms.default',
branch: 'master',
user: {
login: 'su',
idProvider: 'system'
},
principals: ['role:system.admin'],
attributes: {
ignorePublishTimes: true
}
},
() => {
if (event.type === 'node.pushed') {
const contentsPublished = event.data.nodes
// get the id of the first content of the published contents
const contentId = contentsPublished[0].id
const repo = Node.connect({
repoId: 'com.enonic.cms.default',
branch: 'master'
})
// get the first 100 versions
const contentVersions = repo.findVersions({
start: 0,
count: 100,
key: contentId
})
for (let index = 0; index < contentVersions.hits.length; index++) {
const element = contentVersions.hits[index]
const contentOnVersion = Content.get({ key: contentId, version: element.versionId })
// it always printing the same title
log.info(contentOnVersion.data.title + ' index: ' + index)
}
}
}
)
}