Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Set the parent of an existing page type programmatically

Vote:
 

Hi, I want to move a page type under another one. So I tried to change the parent Link as:

productPageType.ParentLink = pageType.ContentLink.ToPageReference();

_migrationHelper.Service.SavePage(productPageType);

The problem is after running the script, I see my page was not moved. 

Can you help me?

Thank you

#181061
Edited, Aug 08, 2017 8:31
Vote:
 
ServiceLocator.Current.GetInstance<IContentRepository>().Move(sourceRef, targetRef, ..)
#181062
Aug 08, 2017 8:45
Vote:
 

Hello Valdis,

Great this work.

I have another question, if possible to set the position/order where the item should be moved in the hieraquicy?

Thank you

#181066
Aug 08, 2017 9:00
Vote:
 

As far as I remember (no compilation done):

var repo = ServiceLocator.Current.GetInstance<IContentRepository>();
var newVersion = page.CreateWritableClone();
newVersion.Property[MetaDataProperties.PagePeerOrder].Value = defaultSortOrder;

repo.Save(...);
#181067
Aug 08, 2017 9:30
Vote:
 

aaaand.... `ServiceLocator` is BAD! :)

use proper dependency injection.

#181068
Aug 08, 2017 9:31
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.