Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have created a "Date Picker With Time" property on my NewsItem documents types, to handle a user editable date for news items.
I do however want that field to automatic get set to the time of the first publish. So i created a CustomEventHandler like this.
public class CustomEventHandlers : ApplicationEventHandler{ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { ContentService.Published += ContentServicePublished; } private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs<IContent> args) { foreach (IContent node in args.PublishedEntities) { if (node.HasProperty("firstPublished") && node.GetValue("firstPublished") == null) { node.SetValue("firstPublished", DateTime.Now); } } }}
But guess what? I won't work. I have debugged the code and the line "node.SetValue" is running? Does the "Date Picker with Time" dont use DateTime data?
Found the error.
You can of couse only set values on the Publishing event, not the Published event i used..
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Set a Date/Time property in code
I have created a "Date Picker With Time" property on my NewsItem documents types, to handle a user editable date for news items.
I do however want that field to automatic get set to the time of the first publish. So i created a CustomEventHandler like this.
But guess what? I won't work. I have debugged the code and the line "node.SetValue" is running? Does the "Date Picker with Time" dont use DateTime data?
Found the error.
You can of couse only set values on the Publishing event, not the Published event i used..
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.