Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!

share|improve this question
    
Did you try debugging it ? You can attach the debugger in VS to the SPTimer process i believe, set a breakpoint in your workflow and triggering it to run. –  Oddmar Dam Nov 19 '12 at 7:41
    
Hi Oddmar, when I tried debugging it it said VS cannot debug and asked me to reinstall VS. I reinstalled it but still the same....weird. –  Lin Zhang Nov 19 '12 at 21:35
    
Do you have an option to try and debug with another computer ? I would try that, just in case there is something wrong with your computer. –  Oddmar Dam Nov 20 '12 at 16:33

1 Answer 1

up vote 0 down vote accepted

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".

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.