ANY ideas on the below problem? It's lengthy, but really weird.
Short version is that event receivers on publishing libraries attached
to ItemUpdating fire twice with random results...
We have a content type with:
-an integer column called "testCount" which defaults to 0
-an html content field called "testText"
We have an event handler attached to itemupdating. It does the following:
(pseudocode shortcuts used, we're getting proper field names/etc, and
there is try/catch around appropriate places)
---------------------CODE-------------------------
DisableEvents();
int counter = Convert.ToInt32(properties.BeforeProperties["testCount"]);
counter++;
properties.AfterProperties["testCount"] = counter;
Debug("Before:" + properties.BeforeProperties["testText"]));
Debug("Item:" + properties.ListItem["testText"]));
Debug("After:" + properties.AfterProperties["testText"]));
properties.AfterProperties["listText"] = "Edited AfterProperties: " +
DateTime.Now;
properties.status = Statuses.Continue
EnableEvents();
---------------------END CODE-------------------------
Note: this is attached to a publishing area with "/Pages" and all the
publishing stuff active. That may or may not be relevant.
Test cases:
-Open a page with count at 0
-Click edit
-Change testTest to "Bill Test A" (then B, then C, etc in subsequent tests)
-Click "check in"
Results:
-testCount goes to 2
-listText SOMETIMES is Bill Test A, sometimes is our datetime set
-our debugging log shows that the handler runs twice
Now, repeat the test with Bill Test B
-testCount goes to 4
-the Before/Item/After debugs happen twice (showing two list runs).
Now for the funny bit:
--it debugs once the OLD date time
--it debugs once "Bill Test B"
-testText DOES wind up as our new dateTime.Now most of the times
Now, repeat the test 5 more times WITHOUT EDITING listText
results:
-testCount sometimes goes up 2, sometimes doesn't go up at all (only
the first two tests always raise testCount)
-Before/Item/After debugs twice each time:
--debugs once "Bill Test B" (a value which hasn't been around for 4
edits by the end!!! remember I'm NOT editing that column)
--debugs once the OLD dateTime string (as you'd expect)
-testText DOES wind up as our new dateTime.Now most of the times
Whiskey Tango Foxtrot, over.
------------------------------------------------------------------- OzMOSS.com
- to unsubscribe from this list, send a message back to the list with
'unsubscribe' as the subject.
Powered by mailenable.com - List managed by www.readify.net