I have a list "Table" this list has associated OOTB Approval Workflow. This list also has two columns "Approval 2010" and "Request Status". When an item is added to the list the workflow starts the process for approving the item and the status of column "Request Status" changes to "Submitted". When the status of column "Approval 2010" change to "Approved" the value of column "Request Status" need to change to "Approved".
I don't receive any error, but the properties.ListItem.Update(); doesn't update the value of column "Request Status".
MyCode: private void ChangeStatus(SPItemEventProperties properties) { try {
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevSite = new SPSite(properties.SiteId))
using (SPWeb elevWeb = elevSite.OpenWeb(properties.RelativeWebUrl))
{
SPList elevList = elevWeb.Lists[properties.ListId];
SPListItem elevListItem = elevList.GetItemById(properties.ListItemId);
//requestStatusValue = elevListItem["Request Status"].ToString();
string value = properties.ListItem["Approval 2010"].ToString();
SPListItem item = properties.ListItem;
using (DisabledEventsScope scope = new DisabledEventsScope())
{
if (value == "16")
{
if (properties.ListItem["Request Status"].ToString() != "Approved")
{
properties.ListItem["Request Status"] = "Approved";
properties.ListItem.Update();
}
}
else if (value == "17")
{
if (elevListItem["Request Status"].ToString() != "Rejected")
{
item["Request Status"] = "Rejected";
elevListItem.Update();
}
}
else if (value == "15")
{
if (elevListItem["Request Status"].ToString() != "Canceled")
{
item["Request Status"] = "Canceled";
elevListItem.Update();
}
}
}
}
});
}
catch (Exception ex)
{
Logger.Error(Title, ex.Message, Category, ex);
properties.ErrorMessage = ex.Message;
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.Cancel = true;
}
finally
{
Logger.Info(Title, "Exit StatusChanged", Category);
}
}