Set a manual order when created some contents

Enonic version: 6.15.5
OS: Windows 10

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?

I don’t see why you cannot use a createdTime, as long as this value does not change when you modify?
Are you using node or content api?

Because the imported contents are changed in some imports. This is an example:

  1. In first call of API I get this data: A, B, C, D.
  2. 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.

What api are you referring to here?

This is an external API that return a JSON.

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?

Are you saying this cannot be done right now?

This is reassuring (and how it should be :slight_smile: )
We are not sure if it is possible or not, but we are not sure how to do it. Do you have any pointers?

We tested using the Repo to modify the node and set the value in _manualOrderValue. This basic example works correctly:

repo.modify({
key: ‘a9da5140-87ae-49a5-bf6e-b5f17cb438d7’, // Static ID
editor: function (node) {
node._childOrder = ‘_manualordervalue ASC’
node._manualOrderValue = 1 // Static value to _manualOrderValue
return node
}
})

But when I put the value in a var, the field receives the value undefined. This is an example in the import:

if (returnedContent) {
repo.modify({
key: returnedContent._id,
editor: function (node) {
node._childOrder = ‘_manualordervalue DESC’
node._manualOrderValue = manualOrderValue
return node
}
})
}

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.

I don’t use the createdTime ASC because this import can include new objects and modify others

You could use “modifiedTime” then. This field is updated for both creation and modification of content.

But if you want it to be only on import time (and not be impacted by other changes), I would do as proposed by Tsi:

  • Create and set a property “importTime”
  • And sort on this property

But when I put the value in a var, the field receives the value undefined

I tried locally with an application containing a task and a global variable and I have no problem of value.

  • Could you copy the entire code of your task?
  • Can you check that repo.modify is called?

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

Example:

node._manualOrderValue = manualOrderValue.intValue()
1 Like

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

node._manualOrderValue = manualOrderValue.intValue()

It works, thanks!

This topic was automatically closed after 8 hours. New replies are no longer allowed.