Try our conversational search powered by Generative AI!

Which value of SaveAction to use?

Vote:
 

We have a scenario where users can create comments against news pages on a web-site.

The comments are created in code as children of the news page, and we require them to be saved as 'Ready to Publish', so an administrator can check them and subsequently publish them.

Following is the code we use to save the comments:

Note that comment submitters  may not be logged in, so we have a a default user (identified by AutomaticCreatorUserName) to save details as.

UnifiedPrincipal currentUser = UnifiedPrincipal.Current;

// Get our 'Auto create' user details from config

string username = SiteSettings.GetSettingString("AutomaticCreatorUserName");

string password = SiteSettings.GetSettingString("AutomaticCreatorPassword");

// Obtain the Iprincipal

IPrincipal principal = AuthenticationProvider.Authenticate(this, username, password);

// Set the CurrentUser to this one

PageBase.CurrentUser = principal as UnifiedPrincipal;

// Load the required page type

PageType commentPageType = PageType.Load(Names.PageTypeNewsComment);

// Create a new Comment page instance

PageData newPage = Global.EPDataFactory.GetDefaultPageData(CurrentPage.PageLink, commentPageType.ID, EPiServer.Security.AccessControlList.NoAccess);

// Set details for the page

newPage.PageName = "Comment created: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();

newPage.VisibleInMenu = false;

((PropertyString)newPage.Property["CommentName"]).Value = txtCommentName.Text;

((PropertyString)newPage.Property["CommentEmail"]).Value = txtCommentEmail.Text;

((PropertyLongString)newPage.Property["CommentText"]).Value = HttpUtility.HtmlEncode(txtCommentText.Text);

// Now save the page

Global.EPDataFactory.Save(newPage, EPiServer.DataAccess.SaveAction.Commit, EPiServer.Security.AccessControlList.NoAccess);

// Restore previous user

PageBase.CurrentUser = currentUser;

 

Our problem is that when a user with sufficient permissions comes to publish the page, a new version of the page is created, and the original version still remains in the Task List. Do we need to use one of the 'Forcexxx' options of SaveAction instead of CheckIn?

#20004
May 16, 2008 18:06
Vote:
 
Forgot to mention - it's EPi 4.62B Smile
#20005
May 16, 2008 18:09
Vote:
 

I've had a look at the Version List for the created page, and there is an additional 'Delayed Publish' button visible (When the page is created, I set the start publsh date to DateTime.Now)

If I click the 'Publish' button in the Version list, the version is published, and the task is removed from the 'My Tasks' list, so I have a workaround, I guess, but I just want to create the page in 'Ready to Publish' mode and have it published from the task list...

#20006
May 16, 2008 19:02
* 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.