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
basically what I want to do is, when a new item is created in the back office of a certain documentype, I want to have some code to run to set the value of a textbox field on that item dynamically (say to be the name of its parent node). Could anyone tell me roughly how I'd go about doing this?
thanks a lot for any help
You are looking for PublishingStrategy
public class Register : ApplicationEventHandler
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
Umbraco.Core.Publishing.PublishingStrategy.Publishing += PublishingStrategy_Publishing;
private void PublishingStrategy_Publishing(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<IContent> e)
foreach (var content in e.PublishedEntities.Where(x => x.ContentType.Alias == "MyDocTypeAlias"))
content.SetValue("MyPropertyAlias", "My New Value Everytime Someone Presses Publish");
Thanks a lot, that worked fine!
Ideally I was hoping it would happen on the creation of the page rather than the publishing but for me this does the job well enough.
FYI - For Umbraco 9+, you can use the EditorModel Notifications to set an initial value on Node loading.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted