I have an import in a task (external API), and I need to create the items in the folder and sort by the order that they come. I don’t use the createdTime ASC because this import can include new objects and modify others (the new objects always have a newer date).
Is there any way to import this and use the manual order when I create the content?
Because the imported contents are changed in some imports. This is an example:
In first call of API I get this data: A, B, C, D.
After time I call API and get this data: E, B, C, D. The content B, C and D are modified and theirs createdTime not changed. The content E is created and have a newest createdTime. The sort in createdTime order is this: B, C, D, E. And this sort is wrongly.
If I understand you correctly, by setting a property in XP i.e. “created” to current time of import, and avoid updating this when modifying items, you can always sort on this property to get the items in the ordner they were created in XP.
Our question is if it is possible to set a folder to “manual” sorting and set the sorting order on the children through code. There are multiple ways with createdTime, attributes with values and similar that almost handles this case, but we just want to set it as manual as this is the only way that solves all our issues. Do we have any way this can be done through code?
Essentially, anything that can be done through Content Studio, can also be done in the underlying API.
Only “exceptions” is if a feature somehow is missing from the JavaScript library for instance?
PS1.: The ‘manualOrderValue’ is an incremental var that I declared in the global context of the task.
PS2.: We tested this approach of many ways (created a separated function, pass the var in the params, …) but not worked.
1)About we use the ‘modifiedTime’ or ‘importTime’, I cannot use these fields, because the user needs to change the order of these contents in the content studio. Because of this, I need to use the manual order.
2)About the code, we created a test of this in a simple task, this code just has the repo.modify:
// This code NOT WORKS
var repo = nodeLib.connect({
repoId: 'cms-repo',
branch: 'draft'
})
var manualOrderValue = 1
manualOrderValue = manualOrderValue + 1
repo.modify({
key: 'a9da5140-87ae-49a5-bf6e-b5f17cb438d7', // Static ID
editor: function (node) {
node._childOrder = '_manualordervalue ASC'
node._manualOrderValue = manualOrderValue
return node
}
})
// This code WORKS
var repo = nodeLib.connect({
repoId: 'cms-repo',
branch: 'draft'
})
var manualOrderValue = 1
repo.modify({
key: 'a9da5140-87ae-49a5-bf6e-b5f17cb438d7', // Static ID
editor: function (node) {
node._childOrder = '_manualordervalue ASC'
node._manualOrderValue = manualOrderValue
return node
}
})
When I tried originally I did it on Enonic XP 7.0 which is using Java 11 (where this problem is solved).
I reproduced your issue on Enonic XP 6.15 (Java 8).
The problem is that after the line
manualOrderValue = manualOrderValue + 1
manualOrderValue is now a floating point number. A quick fix would be to force it to an integer
You might have your reasons like that you are importing a tree of contents or that these contents may have children in the future
But I wanted to point out that
node._childOrder = '_manualordervalue ASC'
is only necessary on the parent content of these manually sorted contents