Search the web
Sign In
New User? Sign Up
sitecore
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Sitecore 5.3 - Default Field value to Today's Date   Message List  
Reply | Forward Message #3286 of 3315 |
Re: Sitecore 5.3 - Default Field value to Today's Date

Hey John,

The item is in all of the newly opened Content Editors, with no data
tree (the site tree), just the lone item. This is just weird, I do
have a OnSave() eventhandler for the same item. It really could be a
phenomena that happens between the two calls. The client really
isn't concerned; in other areas of the application the client
receives error messages from Sitecore and that is when they now that
the function actually worked. lol :) So, this isn't a big deal,
especially with our deadline.

What is concerning me is that the layout from the Master is not being
pulled into the newly created Item. Do I need to call the
base.OnItemCreated()? Or, is there anywhere in the eventHandler that
I need to do something special to insure that the layout is being
created along with the item? I did verify through Sitecore's UI that
the item is inherited from the corect master.

John, thank you for all of your time and intelligence on these
matters!



--- In sitecore@yahoogroups.com, "John West" <johnpwest3@...> wrote:
>
> Does it open the same item in all content editors, or different
items
> (maybe this is a result of default children in your master?).
>
> You may want to use item:added instead of item:created
> (http://sdn5.sitecore.net/FAQ/API/added%20or%20created%20event.aspx)
> or you may have to fall back to item:saved.
>
> Sitecore.DateUtil.IsoNow seems to provide a convenience for getting
> the system date in the required format.
>
> I just tested with a master which had a child, both based on the
same
> template which had a field named ItemCreationDate. I used the
> following configuration and code. I did not experience any issues
> using 5.3.2 071220 - the field was populated for both items and no
new
> content editor windows opened.
>
> <event name="item:created">
> <handler type="Global.Events.ItemEventHandler, Global"
> method="OnItemCreated">
> <FieldName>ItemCreationDate</FieldName>
> </handler>
> </event>
>
> using System;
>
> namespace Global.Events
> {
> public class ItemEventHandler
> {
> private string _fieldName = null;
>
> public string FieldName
> {
> get { return (_fieldName); }
> set { _fieldName = value; }
> }
>
> public void OnItemCreated( object Sender, EventArgs args )
> {
> Sitecore.Diagnostics.Assert.IsNotNull(_fieldName, "Field
> name not provided" );
> Sitecore.Data.Events.ItemCreatedEventArgs cArgs =
> Sitecore.Events.Event.ExtractParameter(args, 0) as
> Sitecore.Data.Events.ItemCreatedEventArgs;
>
> if (cArgs != null && cArgs.Item != null &&
> cArgs.Item.Fields[FieldName] != null &&
> String.IsNullOrEmpty(cArgs.Item.Fields[FieldName].Value))
> {
> cArgs.Item.Editing.BeginEdit();
> cArgs.Item.Fields[FieldName].Value =
> Sitecore.DateUtil.IsoNow;
> cArgs.Item.Editing.EndEdit();
> }
> }
> }
> }
>





Thu Jan 17, 2008 5:27 pm

dice55m
Online Now Online Now
Send Email Send Email

Forward
Message #3286 of 3315 |
Expand Messages Author Sort by Date

Hey All, I am new to Sitecore and I am curious on how to set the default value of a field to Today's Date. Thanks in advance, Wayne...
dice55m
Online Now Send Email
Jan 16, 2008
12:47 am

Hello, This forum has basically been abandoned in favor of the SDN forums: http://sdn5.sitecore.net/Forum.aspx This specific question is probably best...
John West
johnpwest3
Offline Send Email
Jan 16, 2008
1:45 am

Oops. if ( itm.Database.Name.ToLower() == "master" && itm.Fields["myfield"] != null ) That should include checking that the field doesn't already have a value:...
John West
johnpwest3
Offline Send Email
Jan 16, 2008
1:55 am

One more thing I forgot. Sitecore automatically stores the version's creation date in a field named __created (Sitecore.FieldIDs.Created). This may or may not...
John West
johnpwest3
Offline Send Email
Jan 16, 2008
4:01 pm

OK, now I'm even annoying myself. I think you could use item:created instead of item:saved, which should not raise item:created, which should mean you don't...
John West
johnpwest3
Offline Send Email
Jan 16, 2008
4:13 pm

... Appreciate the quick response John. I created the item:created event handler and it works almost perfectly. When I create an item, it successfully...
dice55m
Online Now Send Email
Jan 16, 2008
9:11 pm

That is very weird - I have never seen that before. It could be something else you're working on, or you might try item:saved instead....
John West
johnpwest3
Offline Send Email
Jan 16, 2008
9:15 pm

Does it open the same item in all content editors, or different items (maybe this is a result of default children in your master?). You may want to use...
John West
johnpwest3
Offline Send Email
Jan 16, 2008
11:02 pm

Hey John, The item is in all of the newly opened Content Editors, with no data tree (the site tree), just the lone item. This is just weird, I do have a...
dice55m
Online Now Send Email
Jan 19, 2008
12:33 am

Sorry for the delayed response. Can you explain what you mean by an OnSave event handler? Do you mean an item:saving or item:saved event handler, a processor...
John West
johnpwest3
Offline Send Email
Jan 21, 2008
5:48 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help