I am trying to update a list in a different site using a custom workflow action. The sites are within the same site collection. I have successfully deployed the custom action to the SharePoint server. When I run a workflow that the contains this action, the workflow completes successfully with no errors. I am certain that the action is executing because I see the result of the lines that contain service.LogToHistoryList()
in the workflow history log, and they contain the expected values. The problem is that the target list item is not actually being updated. Below is the section of code that is intended to update the list item.
try
{
ISharePointService service = (ISharePointService)executionContext.GetService(typeof(ISharePointService));
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", SiteUrl, string.Empty);
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", List, string.Empty);
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", Column, string.Empty);
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", Value, string.Empty);
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", updateCol, string.Empty);
service.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowComment, 0, TimeSpan.Zero, "Debugging Output", updateVal, string.Empty);
ClientContext clientContext = new ClientContext(SiteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle(List);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='"+Column+"'/>" +
"<Value Type='String'>"+Value+"</Value></Geq></Where></Query><RowLimit>1</RowLimit></View>";
ListItemCollection collListItem = oList.GetItems(camlQuery);
clientContext.Load(collListItem);
clientContext.ExecuteQuery();
foreach (ListItem oListItem in collListItem)
{
oListItem[updateCol] = updateVal;
oListItem.Update();
clientContext.Load(oListItem);
clientContext.ExecuteQuery();
}
return ActivityExecutionStatus.Closed;
}
catch (Exception ex)
{
ISharePointService service = (ISharePointService)executionContext.GetService(typeof(ISharePointService));
if (service == null)
{
throw;
}
service.LogToHistoryList(this.WorkflowInstanceId,SPWorkflowHistoryEventType.WorkflowError, 0, TimeSpan.Zero,"Error Occurred", ex.Message, string.Empty);
return ActivityExecutionStatus.Faulting;
}