Monday 6 April 2009

Sitecore Item:Saving

Sitecore has a wonderful system to add your code to specific events. I have used Item:Saving to summarize some content fields into one specific field which we used for indexing. That worked great.

Recently I received a request to do some more sophisticated checks on some fields and deny saving when something does not fit.

I remembered my OnItemSaving method and added some code to it, but when something went wrong, the message box telling the error came twice.

After some debugging I found that the code really gets called twice. But why?

Try yourself – check your web.config and set <events timingLevel="custom"> to <events timingLevel="high">. Modify an item, save it and check your log file:

Event started: item:creating
Event ended: item:creating. Elapsed: 0.00838095344520044
Event started: item:created
Event ended: item:created. Elapsed: 0.00502857206712026
Event started: item:versionAdding
Event ended: item:versionAdding. Elapsed: 0.00474920695228025
Event started: item:saving
Event ended: item:saving. Elapsed: 0.00586666741164031
Event started: item:saved
Event ended: item:saved. Elapsed: 419.566732643395
Event started: item:versionAdded
Event ended: item:versionAdded. Elapsed: 0.00474920695228025
Event started: item:added
Event ended: item:added. Elapsed: 0.00502857206712026
Event started: item:saving
Event ended: item:saving. Elapsed: 0.00419047672260022
Event started: item:saved
Event ended: item:saved. Elapsed: 98.5195045739054

Any Idea? :-)

4 comments:

ediT said...

I know this is a bit old, but it's one of the only things I found when I was search about the double save events.

If you look at the IDs of the items that are being saved, you should see that they are different. The full path of one of the items starts off with '[orphan]'. I'm not too good with Sitecore yet, so I don't know what that means, but I just filtered my save action code to only apply to items whose full path started with what I expected.

Hope that give someone some help.

-=ZloGlaZ=- said...

You can try to run the "Clean Up Databases" task (Sitecore->Control Panel->Database)to clean the [orphan] items.

Anonymous said...

I had the same issue with the [orphan] records, turned out to be corrupt shadows table.

truncated the shadows table in master, and truncated the links table in core, rebuild the links database, and problem went away.

Unknown said...

Clean up databases didn't work for me but truncating the shadows table (master) and links table (core) did. Really happy about that as I've been running scripts across the whole content tree so I can simply the workflow and could not figure out how to deal with these orphans. Cheers