Manotas
2010-06-09 08:18:30 UTC
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);
}
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);
}