I'm using SharePoint 2013 on-premise with Nintex 2013. I have a list (List A) that has a workflow attached which is associated to a 2010 Task list, (Task List A). I have a requirement to update an item in List A when the itemAdded or itemUpdated event fires on 'Task List A'. I need to copy the contents of the Task lists 'Assigned To' (person) column to the List A 'Assigned To' (text) Column. I've set the feature to attach to the Task List A list only by using "" in the Elements.xml file. I verified that the Event Receiver is attaching to the task list by using SharePoint Manager, however no update is being made. I have not written SP Code in a while so I'm likely missing something pretty simple.
My code for the itemUpdated is as follows:
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
string itemRC = "";
SPWeb web = properties.OpenWeb();
//get item id from Task List field
SPList Tasklist = web.Lists[properties.ListId];
SPListItem item = properties.ListItem;
itemRC = item["RelatedContent"].ToString();
//get the current assigned to value
string itemAssignedTo = item["Assigned To"].ToString();
//pull the ID value of the Item from the RelatedContent QS
string stritemID = itemRC.Substring(itemRC.LastIndexOf("=") + 1);
Int32 intItemID = Int32.Parse(stritemID);
//get related item list
SPList itemList = properties.Web.Lists["Lists/List A"];
//get other list item to update with the value from the current list
try {
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Id'/><Value Type='Number'>" + intItemID + "</Value></Eq></Where>";
SPListItemCollection items = itemList.GetItems(query);
SPListItem itemListItem = items[0];
string AssignedToInternalName = itemListItem.Fields["Assigned To"].InternalName;
itemListItem[AssignedToInternalName] = itemAssignedTo;
properties.Web.AllowUnsafeUpdates = true;
EventFiringEnabled = false;
itemListItem.Update();
EventFiringEnabled = true;
properties.Web.AllowUnsafeUpdates = false;
}
catch (Exception ex)
{
throw ex;
}
}