Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Phill 115 posts 289 karma points
    Jan 21, 2014 @ 19:20
    Phill
    0

    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);

    }

    }

    }

    }

  • keilo 568 posts 1023 karma points
    Aug 30, 2014 @ 20:58
    keilo
    0

    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.

     

Please Sign in or register to post replies

Write your reply to:

Draft