Updating list items on another site within the same site collection using a custom workflow action

I am trying to update a list on another site using a special workflow action. Sites are within the same site collection. I have successfully deployed custom actions on a SharePoint server. When I start a workflow that contains this action, the workflow completes successfully without errors. I am sure that the action is performed because I see the result of the lines that contain service.LogToHistoryList()the history of workflows in the log, and they contain the expected values. The problem is that the goal list item is not actually being updated. The following is a snippet of code that is designed to update a 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;

        }
+4
1

, , . Server, . . .

using (SPSite _site = new SPSite(SiteUrl))
            {
                using (SPWeb _web = _site.OpenWeb())
                {
                    SPList oList = _web.Lists[List];
                    SPQuery _query = new SPQuery();

                    _query.Query = "<Where><Eq><FieldRef Name='"+Column+"' /><Value Type='Text'>"+Value+"</Value></Eq></Where>";
                    SPListItemCollection _itemCollection = oList.GetItems(_query);

                    if (_itemCollection.Count > 0)
                    {
                        _web.AllowUnsafeUpdates = true;

                        foreach (SPListItem Item in _itemCollection)
                        {
                            Item[updateCol] = updateVal;
                            Item.Update();
                        }

                        _web.AllowUnsafeUpdates = false;
                    }
                }
            }
+2

All Articles