HI,
I have a team site.
I have a custom list. In the Item Added event, I am getting the error in the ULS Logs as :
1) System.ArgumentException: Value does not fall within the expected range.
at Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem.
2) <nativehr>0x80070057</nativehr><nativestack></nativestack>
I have the used the code as below in the Item Added event:
public override void ItemAdded(SPItemEventProperties properties) { SPListItem currentItem = properties.ListItem; SPQuery testQuery = new SPQuery(); SPList testList = null; SPListItem testItem = null; SPWeb currentSite = properties.Web; if (currentSite != null) { testList = currentSite.Lists.TryGetList("Test List"); } if (testList != null) { testQuery.Query = "<Where><Eq><FieldRef Name=\"TestStatus\" /><Value Type=\"Text\">Progress</Value></Eq></Where>"; SPListItemCollection nextItemCollection = testList.GetItems(testQuery); int CountItems = nextItemCollection.Count; if (CountItems >= 1) { testItem = nextItemCollection[0]; currentItem["Title"] = testItem["Title"]; currentItem.Update(); testItem["TestStatus"] = "Done"; testItem.Update(); } } }
I have verified that the columns exist in the list. 60% of the time the code works, 40% of the time the code errors out.
What am I missing?
Thanks