Getting page name as date field

Jon White asked on March 9, 2017 12:54

Hi,

I have a custom page type with a data type of 'date', and calendar control.

When selected I can show the date in repeater a-ok.

But I want the date of this field to be the name of the page in the content tree.

I've tried the 'Page name source field:' but it doesn't allow me to select this field as the page name source. I've ticked 'required' and nothing.

Does this mean I can't do this? Or is there something I'm missing.

Thanks in advance Jon

Recent Answers


Peter M answered on March 9, 2017 13:34 (last edited on March 9, 2017 13:42)

If I understand you correctly you want your page name to be equal the value of date time field i.e.Image Text

You probably need to use global events here For example on document save event - update your document name:

[CustomRequestEventsHandler]
public partial class CMSModuleLoader
{
    /// <summary>
    /// Attribute class that ensures the loading of custom handlers
    /// </summary>
    private class CustomRequestEventsHandlerAttribute : CMSLoaderAttribute
    {
        /// <summary>
        /// Called automatically when the application starts
        /// </summary>
        public override void Init()
        {
            DocumentEvents.Update.After += (sender, args) =>
            {
                TreeNode node = args.Node;
                if (node != null) // DocumentUpdateBeforeEventHandler(node);}
                {
                    if (node.ClassName == "MyClassName")
                    {
                        node.DocumentName = node.GetValue("MyDate").ToString();
                    }

                    // other code
                    node.Update();
                }


            }
        }
    }
  }
0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 9, 2017 13:59

Make the field requires, then make the field type a text field, then put a default value of ##TODAY## for the field. Should auto populate the field with today's date/time.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.