Quantcast
Channel: SharePoint 2010 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 17574

Workflow keeps bringing up error

$
0
0

I wrote a simple workflow in VS2010, but it keeps throwing an error, just says "An error occurred on [my workflow]." The function is this: I have a list, three columns: Title, Req Number, and Archive. Title is just the title, Req Number is  an identifying number, and archive either says "current" or "archived." When someone adds an item, it should look to see if there exists an item with the same Req number, and if so it changes the archive column from "current" to"archived." Thanks for your help!

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;

namespace WorkflowProject2.Workflow1
{
    public sealed partial class Workflow1 : SequentialWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }

        public Guid workflowId = default(System.Guid);
        public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();

        private void archivePreviousItems(object sender, EventArgs e)
        {
            SPWeb currentSite = SPContext.Current.Site.RootWeb;
            SPList myList = currentSite.Lists["Test List"];

            String queryString = "<Where><Eq><FieldRef Name='Req Number'>";
            queryString += "<Value Type='Text'>";
            queryString += workflowProperties.Item["Req Number"].ToString();
            queryString += "</Value></Eq></Where>";

            SPQuery findItemsQuery = new SPQuery();
            findItemsQuery.Query = queryString;
            SPListItemCollection listItems = myList.GetItems(findItemsQuery);

            foreach (SPItem currentItem in listItems)
            {
                if (!currentItem.Equals(workflowProperties.Item))
                {
                    currentItem["Archive"] = "Archived";
                    currentItem.Update();
                }
            }
        }
    }
}




Viewing all articles
Browse latest Browse all 17574

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>