I'm looking for some help with setting default value for a field when creating a content node. According to this issue U4-3695 I should be able to do this using CreateContent method (unless Shannon really meant 7.1 and not 7.01 for this to be available).
The closest I've been able to come is using the ContentService.Saving method, as Creating and Created are both marked as obsolete so I can't use them. However with my sample code below my default date value is always null and it always gets set too late (obvioiusly) so I can't use required field option as there's no way to set the default value when creating node. I'm still quite new to v7/Belle/Angular etc so any help would be greatly appreciated.
public class CustomEventHandlers : IApplicationStartupHandler
Have you figured this out? Im too trying to create a new sub-page with specific docalias on page creation (i.e Create sub-node Archives when ArticleCategory node created).
Tried the advised new Saving event without success.
If you have figured the solution or any pointers would be greatly appreciated.
Looking for help with CreateContent method
Hi there,
I'm looking for some help with setting default value for a field when creating a content node. According to this issue U4-3695 I should be able to do this using CreateContent method (unless Shannon really meant 7.1 and not 7.01 for this to be available).
The closest I've been able to come is using the ContentService.Saving method, as Creating and Created are both marked as obsolete so I can't use them. However with my sample code below my default date value is always null and it always gets set too late (obvioiusly) so I can't use required field option as there's no way to set the default value when creating node. I'm still quite new to v7/Belle/Angular etc so any help would be greatly appreciated.
public class CustomEventHandlers : IApplicationStartupHandler
{
public CustomEventHandlers()
{
//Initialize the event subscriber
ContentService.Saving += ContentService_Saving;
}
private void ContentService_Saving(IContentService sender, Core.Events.SaveEventArgs e)
{
if (e.SavedEntities.FirstOrDefault().ContentType.Alias == "myPageType")
{
if (String.IsNullOrEmpty(e.SavedEntities.FirstOrDefault().GetValue("myDefaultDate"))) {
e.SavedEntities.FirstOrDefault().SetValue("myDefaultDate", DateTime.Now);
}
}
}
}
Hi Phil
Have you figured this out? Im too trying to create a new sub-page with specific docalias on page creation (i.e Create sub-node Archives when ArticleCategory node created).
Tried the advised new Saving event without success.
If you have figured the solution or any pointers would be greatly appreciated.
is working on a reply...