Freigeben über


Publishing start and end dates are set brute force

When setting publishing start and end dates on a publishing page, these dates will be saved in the PublishStartDate and PublishEndDate fields of the publishing page. Changing the scheduling settings will result in an immediate change of the page (with the modified by and modified date properties set as well), regardless of the state of the page (draft, pending, etc.).

An interesting anomaly I have faced recently (and the source of this discovery) was that when using custom field controls to values of some custom fields and trying to access the values of PublishStartDate or PublishEndDate, these fields contain the values that were present on the ListItem when the pagelayout used to edit the publishing page has loaded.

So imagine the following flow of user actions:

  1. Open page for editing
  2. Use the Schedule button in the ribbon
  3. Set some scheduling dates and click ok
  4. The modal dialog disappears (and your page loads some info through JavaScript from the server)
  5. Save the page
  6. Field controls are asked to provide values of their controls so these can be saved to the appropriate field

At this point I would expect that the following code would return the dates set in step 3:

    1: public override object Value
    2: {
    3:     get
    4:     {
    5:         SPFieldDateTime pubStart = base.Fields.GetFieldByInternalName("PublishStartDate") as SPFieldDateTime;
    6:         return ListItem[pubStart.Id];
    7:     }
    8:     set
    9:     {
   10:         base.Value = value;
   11:     }
   12: }

Interestingly this is not the case, the values set in step 3 are not retained. My logic would tell me that the ListItem object would be built from scratch at step 5 resulting in the query of properties (changed in step 3). Any ideas what’s happening here?

Comments

  • Anonymous
    October 11, 2012
    Here is what I do:SPListItem listItem = SPItemProperties.ListItem;           if (ScheduledItem.IsScheduledItem(listItem))           {               ScheduledItem scheduledItem = ScheduledItem.GetScheduledItem(listItem);                   var startDate = scheduledItem.StartDate;                   var startDate = scheduledItem.EndDate;           }