Updating a page through the page service

Litium version: [8.5]
Hi,

I’m trying to create a new endpoint to update pages using a certain page template.
When doing this i first get the page and make a writeable clone, i then update and map to the object before using pageService.Update to send the updated page to Litium.

        Page page = _pageService.Get(new Guid(newsItemId));
        var writeablePage = page.MakeWritableClone();
        var updatedPage = UpdateAndMapToPage(writeablePage, newsItem);
        using (_securityContextService.ActAsSystem())
        {
            _pageService.Update(updatedPage);
        }

In my function i update the fieldvalues in the following way:

page.Id = news.Title;
page.Fields.AddOrUpdateValue("Introduction", "Sv-SE", news.Introduction);

The issue i run into is that i can’t see my changes in the Litium Back-office. If i get the page from the Litium admin web API i can see that the changes i’ve made has overwritten the old values, but if i go to the BO i can not see any changes made to the fields, only the page Id. I’ve made sure it’s not an issue with it being cached. I also recieve no errors and nothing weird in the log file.

Is there some form of flag i’m missing that needs to be included for the changes to take effect in the BO?

Thanks in advance!

Typically, as soon as I typed it we figured it out. Instead of using the pageService I used the draftPageService. Will post the solution below if someone runs into a similar issue in the future:

        DraftPage page = _draftPageService.Get(new Guid(newsItemId));
        var writeablePage = page.MakeWritableClone();
        var updatedPage = UpdateAndMapToPage(writeablePage, newsItem);
        using (_securityContextService.ActAsSystem())
        {
            _draftPageService.Update(updatedPage);
            _draftPageService.Publish(updatedPage);
        }

Still mapped to the DraftPage object the same way as before.

2 Likes

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