Lin Zhang
Lin Zhang

Reputation: 31

Visual Studio 2010 / SharePoint 2010 Workflow Error

I have created a simple workflow in VS 2010. What it does is creating a task for a person, when the person changes the task status to "Complete", it logs a message to workflow history.

When I change the status to complete, it says: "An error has occurred in xxxx (the workflow name)".

Code:

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 onWorkflowActived(object sender, ExternalDataEventArgs e)
     {

    }

    public Guid taskID = default(System.Guid);
     public SPWorkflowTaskProperties taskProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
     private bool taskHasCompleted = false;

    public SPWorkflowTaskProperties taskAfterProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
     public SPWorkflowTaskProperties taskBeforeProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
     public String taskOutcome = default(System.String);
     public Guid TaskStatusFieldID = new Guid("c15b34c3-ce7d-490a-b133-3f4de8801b76");  

    private void createTask1_MethodInvoking(object sender, EventArgs e)
     {

        taskID = Guid.NewGuid();
         taskProperties.AssignedTo = "spdev\\lzhang";
         taskProperties.Description = "Please review";
         taskProperties.Title = "Leave application";

    }

     private void completeTask1_MethodInvoking(object sender, EventArgs e)
     {
         // Finalize the task:
         taskAfterProperties.PercentComplete = 100;
         taskOutcome = "Completed";
     }

    private void notComplete(object sender, ConditionalEventArgs e)
     {
         e.Result = !taskHasCompleted;    // **(A)**
     }
     private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
     { 
        string taskStatus = taskAfterProperties.ExtendedProperties[TaskStatusFieldID].ToString();

        if (taskStatus == "Completed")
         {
             taskHasCompleted = true;     // **(B)**

        }

    }

}
 }

I have a feeling that there must be some problem with (A) or (B) but I don't know how to fix it. I didn't find any error in the log file in the 14/LOGS folder...

I appreciate any help! Thanks!

Upvotes: 2

Views: 2301

Answers (4)

Rare Solutions
Rare Solutions

Reputation: 84

To get the current task id in the workflow, I recommend to read the post http://blog.technovert.com/2013/12/solved-taskid-without-using-ontaskcreated/

Upvotes: 0

user1211929
user1211929

Reputation: 1190

Yes, you need to fill it with a GUID, in Visual Studio select Tools, Create Guid and in the new window choose registry format, select copy and paste where all the 0s are.

Alternately select the [ …] and in the new box select bind to a new member and create field. It might be called something like createTask1_TaskId1, finally in the code behind within the createTask1method _invoking make sure you assign a new Guid just like this:

 createTask1_TaskId1 = Guid.NewGuid();

The second option makes sure that multiple tasks created by the same workflow do not freeze.

Upvotes: 1

Lin Zhang
Lin Zhang

Reputation: 31

I have found the problem! It was because in "Workflow1.cs[design]" (the design view) I didn't specify the TaskID for "completeTask1" in the "Properties box". By default it is "00000000-0000-0000-000000000000", I should have changed it to "taskID".

Upvotes: 1

user1211929
user1211929

Reputation: 1190

I had quite few problems with Visual Studio and Workflows, most of them is due not assign the right task ids or forgetting to create an after properties for the task changed or a correlation token or other small things.

So the problem you are facing seems to fall under this category rather than having a problem with the code behind.

Try with this guide and make sure every step is done: http://dotnetadil.wordpress.com/2012/05/29/sharepoint-foundation-2010-visual-studio-approval-workflow/

Or even better the Microsoft step by step guide:

http://msdn.microsoft.com/en-us/library/hh824675.aspx

Another thing I would try out is to create your workflow and make sure that the exit condition is set to true, so you can check if the structure is done correctly

Upvotes: 1

Related Questions