# New page should be created first and not last in CMS tree page view

**URL:** <https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268>\
**Category:** Questions\
**Tags:** litium-6\
**Created:** [December 19, 2019, 3:14pm UTC](https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268 "2019-12-19T15:14:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cissi](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/cissi/32/18_2.png) [@Cissi](https://forum.litium.com/u/Cissi)\
**Post date:** [December 19, 2019, 3:14pm UTC](https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268/1 "2019-12-19T15:14:35Z")

</div>

Hi!  
I know its possible to modify but I cant any information about it. When creating a new page in the CMS the page should be created first and not last in the list of pages.

Litium version: 6.3.7

---

<div class="post-metadata">

**Author:** ![Cissi](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/cissi/32/18_2.png) [@Cissi](https://forum.litium.com/u/Cissi)\
**Post date:** [December 20, 2019, 10:37am UTC](https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268/2 "2019-12-20T10:37:57Z")

</div>

I solved it myself.

```
  public EventHandlerStartup()
    {
        ModuleCMS.Instance.EventManager.PageCreated += EventManagerOnPageEvent;
    }

    private void EventManagerOnPageEvent(Guid webSiteId, Guid pageId, Guid parentPageId)
    {
        var token = ModuleCMS.Instance.AdminToken;
        var currentPage = Page.GetFromID(pageId, token);
        var parentPage = currentPage.GetParentPage(token);

        try
        {
            currentPage.Move(parentPage, 0, token);
        }
        catch(Exception e)
        {
            Solution.Instance.Log.CreateLogEntry("PageCreated could not be added first", e, LogLevels.ERROR);
        }
    }
```

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [December 20, 2019, 11:08am UTC](https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268/3 "2019-12-20T11:08:50Z")

</div>

To think on is that in a multiserver setup the `PageCreated` event will be fired in every node, this move-command without synchronization between node may fail in some nodes that will reflect in false-positive error-logs.

---

<div class="post-metadata">

**Author:** ![Cissi](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/cissi/32/18_2.png) [@Cissi](https://forum.litium.com/u/Cissi)\
**Post date:** [December 20, 2019, 12:48pm UTC](https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268/4 "2019-12-20T12:48:38Z")

</div>

@patric.forsgard Do you have any recomendations? Or should I just nog log anything?

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [December 20, 2019, 2:04pm UTC](https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268/5 "2019-12-20T14:04:08Z")

</div>

Some alternatives can be:

- use a distributed lock that only allowing one node to do the operation at a time
- fetch the page when exception is thrown and check if the index of the page is the expected and if not try again or write to log
- ignore the logging or log with a smaller severity if you what to the log information there when you tryout on local computer

---

<div class="post-metadata">

**Author:** ![Spotonkastebo](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/spotonkastebo/32/717_2.png) [@Spotonkastebo](https://forum.litium.com/u/Spotonkastebo)\
**Post date:** [January 8, 2020, 1:27pm UTC](https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268/6 "2020-01-08T13:27:32Z")

</div>

Can’t you just have a startuptask with the event handler that is set to only run on one machine?

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [January 8, 2020, 2:52pm UTC](https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268/7 "2020-01-08T14:52:04Z")

</div>

Yes, you can. But if that machine is down for maintenance or upgrade and not catching that event the page will still be in the bottom of the list.

---

<div class="post-metadata">

**Author:** ![Cissi](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/cissi/32/18_2.png) [@Cissi](https://forum.litium.com/u/Cissi)\
**Post date:** [January 8, 2020, 3:37pm UTC](https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268/8 "2020-01-08T15:37:45Z")

</div>

Thanks! 😀

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [February 5, 2020, 3:37pm UTC](https://forum.litium.com/t/new-page-should-be-created-first-and-not-last-in-cms-tree-page-view/1268/9 "2020-02-05T15:37:48Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
