Discussion:
SPItem receiver AfterProperties.count=0 ItemUpdating + Custom List
(too old to reply)
Manotas
2010-06-09 08:18:30 UTC
Permalink
Hi,
I have created a 2 custom lists and I would like to update the content in
one based on changes done on list2. To achieve this I'll will need cath new
and old values on the listItem which is being updated, to then find its
equivalent in list2 and proceed to update. I have already attached list1 to a
event handler but I cannot recover both values to complete my task.... If I
override the ItemUpdating event I'm able to get the old value but not the new
one, and when I override the ItemUpdated I can get only the new value.

Mainly my issue is that no matter which of the 2 events I override the count
of the AfterProperties and BeforeProperties hashTables is always 0.... Does
anyone has an idea on what I'm doing wrong ? Here an snippet of my code ....

Thanks in advance






public override void ItemUpdated(SPItemEventProperties properties)
{


SPList lstAnswers = Lists.TPAnswers.GetAnswersList(properties);
SPListItem itemQuestion = properties.ListItem;
SPFieldText fldQuestion =
itemQuestion.Fields.GetFieldByInternalName("Title") as SPFieldText;
string questionStr = string.Empty;
if (fldQuestion != null)
{
questionStr =
fldQuestion.GetFieldValueAsText(itemQuestion[fldQuestion.Id]);

// Check if different than before
string oldValue =
properties.BeforeProperties["vti_title"].ToString();
if (oldValue != questionStr)
{
if (!Lists.TPAnswers.UpdateQuestionColumn(properties,
lstAnswers, questionStr, oldValue))
{
// To handle
}
}
}

base.ItemUpdated(properties);
}



I also tried this :

public override void ItemUpdating(SPItemEventProperties properties)
{
SPList lstAnswers = Lists.TPAnswers.GetAnswersList(properties);
SPListItem itemQuestion = properties.ListItem;
SPFieldText fldQuestion =
itemQuestion.Fields.GetFieldByInternalName("Title") as SPFieldText;
string questionStr = string.Empty;
if (fldQuestion != null)
{
questionStr =
fldQuestion.GetFieldValueAsText(itemQuestion[fldQuestion.Id]);

// Check if different than before
string oldValue =
properties.AfterProperties["vti_title"].ToString();
if (oldValue != questionStr)
{
if (!Lists.TPAnswers.UpdateQuestionColumn(properties,
lstAnswers, questionStr, oldValue))
{
// To handle case
}
}
}
base.ItemUpdating(properties);
}
Nix Halcyon
2010-09-01 12:36:40 UTC
Permalink
In the interest of completeness, I'm going to post an answer to this question, even though the question was months ago...

properties.AfterProperties is only available in the ItemUpdated event. properties.BeforeProperties is only available in the ItemUpdating event. ... you're getting a count of zero because you're querying the wrong one in each method.

Since the BeforeProperties and the AfterProperties are never available at the same time, in order to accomplish your task you will have to rig some logic to cache the BeforeProperties during the ItemAdding event and then retrieve them during the ItemAdded event...and make sure you are talking about the SAME item in both cases. One possible tactic is to create an additional column that you can use to hold a string representation of the data in the other columns you want to compare. Populate that column during ItemAdding and read it again during ItemAdded.

~N
Post by Manotas
Hi,
I have created a 2 custom lists and I would like to update the content in
one based on changes done on list2. To achieve this I will will need cath new
and old values on the listItem which is being updated, to then find its
equivalent in list2 and proceed to update. I have already attached list1 to a
event handler but I cannot recover both values to complete my task.... If I
override the ItemUpdating event I am able to get the old value but not the new
one, and when I override the ItemUpdated I can get only the new value.
Mainly my issue is that no matter which of the 2 events I override the count
of the AfterProperties and BeforeProperties hashTables is always 0.... Does
anyone has an idea on what I am doing wrong ? Here an snippet of my code ....
Thanks in advance
public override void ItemUpdated(SPItemEventProperties properties)
{
SPList lstAnswers = Lists.TPAnswers.GetAnswersList(properties);
SPListItem itemQuestion = properties.ListItem;
SPFieldText fldQuestion =
itemQuestion.Fields.GetFieldByInternalName("Title") as SPFieldText;
string questionStr = string.Empty;
if (fldQuestion != null)
{
questionStr =
fldQuestion.GetFieldValueAsText(itemQuestion[fldQuestion.Id]);
// Check if different than before
string oldValue =
properties.BeforeProperties["vti_title"].ToString();
if (oldValue != questionStr)
{
if (!Lists.TPAnswers.UpdateQuestionColumn(properties,
lstAnswers, questionStr, oldValue))
{
// To handle
}
}
}
base.ItemUpdated(properties);
}
public override void ItemUpdating(SPItemEventProperties properties)
{
SPList lstAnswers = Lists.TPAnswers.GetAnswersList(properties);
SPListItem itemQuestion = properties.ListItem;
SPFieldText fldQuestion =
itemQuestion.Fields.GetFieldByInternalName("Title") as SPFieldText;
string questionStr = string.Empty;
if (fldQuestion != null)
{
questionStr =
fldQuestion.GetFieldValueAsText(itemQuestion[fldQuestion.Id]);
// Check if different than before
string oldValue =
properties.AfterProperties["vti_title"].ToString();
if (oldValue != questionStr)
{
if (!Lists.TPAnswers.UpdateQuestionColumn(properties,
lstAnswers, questionStr, oldValue))
{
// To handle case
}
}
}
base.ItemUpdating(properties);
}
Submitted via EggHeadCafe - Software Developer Portal of Choice
Composite UI Pattern and RAD Development for Data Entry Applications, Part 1
http://www.eggheadcafe.com/tutorials/aspnet/a119aebe-7478-4aaa-b415-12786ec5cf90/composite-ui-pattern-and-rad-development-for-data-entry-applications-part-1.aspx
ds sd
2010-09-13 09:18:20 UTC
Permalink
My current project requires ability to display choice column value via
color or image associated with a choice

But Sharepoint standard packaged misses that control

I am looking for available solutions on market

I came across
http://sharepointfields.com>

Does anybody has experiece using it?

Loading...