Batch Updating pages through code

Vote:
 

So I have a page model for Articles and several existing articles.   I've created a new field for Blog Categories that I want to batch update based on another field in the page model.   I'm having trouble applying the update and publishing.

This is my new field.

        [Display(GroupName = SystemTabNames.Content, Name = "Selected Blog Categories", Order = 5)]
        [SelectMany(SelectionFactoryType = typeof(BlogCategorySelectionFactory))]
        public virtual IList<string> ArticleBlogCategories { get; set; }

Here's the code snippet that is applying the update.   Currently I'm just updating one article to test.

                if (!string.IsNullOrEmpty(blogCategoryNames))
                {

                    var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
                    var editPage = contentLoader.Get<ArticlePage>(childPage.ContentLink);
                    var writableClone = editPage.CreateWritableClone() as ArticlePage;

                    writableClone.ArticleBlogCategories = new List<string>();
                    string[] arrayCategories = blogCategoryNames.Split(',');
                    foreach (var sub in arrayCategories)
                    {
                        writableClone.ArticleBlogCategories.Add(sub);
                    }

                    contentRepository.Save(writableClone, SaveAction.Publish | SaveAction.ForceNewVersion, AccessLevel.FullAccess);

                }

The code seems to execute fine, but when I go back to the page in the CMS, all of the fields are cleared and I cannot publish anymore but somehow I see the text in the presentation.   I have to revert back to the previous published version.   I only want to update this ArticleBlogCategories field.   When I create the WriteableClone, all of the fields seem to be there but the issues happen after the save.   Is there a problem with the syntax of the last line for contentRepository.Save?

#331628
Edited, Oct 18, 2024 13:11
Vote:
 

You have a value and text of selectitem in your selection factory and they are not same, and when you are trying to save using code, you are adding "text" instead of "value" for the categories? Because when you use the CMS UI, it uses the value of the checkbox to store in property.

Or else it is possible you have a draft version when you are seeing the page in CMS vs a published version?

#331746
Oct 20, 2024 23:04
* 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.