The sorting and moving elements in a network is not doable as of today directly via services as we don't have something similar to InsertAtIndex or MoveToIndex type of services.
It's worth noting that the Network order is generated by the order of adding the elements - there's no order or index attribute per node.
The moving we do in Composer is just a graphic client-side move,and once the network it's saved you'll observe the whole object being PUT to the platform with the nodes in a different order.
As you detected, you have couple options:
0. sort in services in composer before displaying - as my colleague suggested. I haven't tested this, but it is worth investigating before jumping in the other options.
1. remove a node then add all its children back in the order you want, one by one. Basically the resulting order is driven by the order in which you insert elements. This I believe can be done with the existing services.
2. considering the fact we don't have an order attribute and the fact we store in XML - network being very simple as structure, you can use the E4X syntax (methods like insertChildBefore and more) to insert an element at a specific location in the XML structure. This is a bit more complex, but effectively it's really easy to implement
I am aware the E4X syntax is typically not that used, so a good quickstart page is this in case it's needed.
The following code assumes two children at the same level.
let str_EntityFileName="Networks_netw(3).xml"; //Export To Source Control of the Network entity;
let str_FileRepositoryName = "SystemRepository";
//1. Load the file as XML
let xml = Things[str_FileRepositoryName].LoadXML({
path: str_EntityFileName /* STRING */
});
//2. Retrieving network Connections
let connections = xml.*::Networks.*::Network.*::Connections;
//3. Locate the node I want to move
let nodeIWantToMove = connections.Connection.(@to=="asdasda");
//4. Duplicate this node as a new object because it's going to be deleted in the next step and it will become null
let newNode=new XML(nodeIWantToMove.toXMLString());
//5. Delete the node I want to move
delete nodeIWantToMove[0];
//6. Locate the target node
let nodeTarget = connections.Connection.(@to=="AuditPurgeScheduler")[0]
//7. Insert the node I want to move above the target node
connections.insertChildBefore(nodeTarget, newNode);
//8. Save the Network entity.Ready for Import.
Things[str_FileRepositoryName].SaveXML({
path: str_EntityFileName /* STRING */,
content: xml.toXMLString() /* XML */
});
Hope this helps