Open Project and view Flow Chart
Open Workflow1.cs
In method createTask1_MethodInvoking Delete all code and
replace by this segment code
private void
createTask1_MethodInvoking(object sender, EventArgs e)
{
try
{
//Create a new TaskId for the Task
this.createTask1_TaskId1 = Guid.NewGuid();
//TaskProperties field is used to configure
the Task Details.
this.createTask1_TaskProperties1.Title =
"General Direct Manage Review";
//You can assign a Task to an user or to a
group.
//Here we assign the task to Direct manager
User
this.createTask1_TaskProperties1.AssignedTo
= "quochung-axioo\\Instructor";
//Task Type corresponds to TaskURN specified
in Elements.xml
this.createTask1_TaskProperties1.TaskType
= 1;
this.createTask1_TaskProperties1.DueDate
= DateTime.Today.AddDays(5.0);
}
catch (Exception
ex)
{
//Logging is used so that we can debug the
errors in the workflow.
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription = ex.StackTrace;
}
}
In method onTaskChanged1_Invoked Delete all code and replace
by this segment code
private void
onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
this.onTaskChanged1_AfterProperties1 = this.onTaskChanged1.AfterProperties;
this.onTaskChanged1_BeforeProperties1 = this.onTaskChanged1.BeforeProperties;
//Set the PercentComplete property to 1.0
(i.e. 100%)
//to indicate that the task has been
completed.
this.onTaskChanged1_AfterProperties1.PercentComplete
= (float)1.0;
}
catch (Exception
ex)
{
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription =
ex.StackTrace;
//throw ex;
}
}
In method ReadyForReview Delete all code and replace by this
segment code
private void
ReadyForReview(object sender, ConditionalEventArgs e)
{
try
{
if (this.onTaskChanged1_AfterProperties1.PercentComplete
== (float)1.0 )
//&&this.onTaskChanged1_AfterProperties1.
//ExtendedProperties["Status"].ToString().Contains("Approve")
{
e.Result = true;
}
else
{
e.Result = false;
}
}
catch (Exception
ex)
{
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com
Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription =
ex.StackTrace;
}
}
In method createReviewTask_MethodInvoking Delete all code
and replace by this segment code
private void
createReviewTask_MethodInvoking(object sender, EventArgs e)
{
try
{
//Create a new TaskId for the Task
this.createReviewTask_TaskId1 = Guid.NewGuid();
//TaskProperties field is used to configure
the Task Details.
this.createReviewTask_TaskProperties1.Title
= "HR Manager Review";
//You can assign a Task to an user or to a
group. Here we assign the task to HR User
this.createReviewTask_TaskProperties1.AssignedTo
= "quochung-axioo\\Learner";
//Task Type corresponds to TaskURN specified
in Elements.xml
this.createReviewTask_TaskProperties1.TaskType
= 2;
this.createReviewTask_TaskProperties1.DueDate
= DateTime.Today.AddDays(2.0);
}
catch
(Exception ex)
{
//Logging is used so that we can debug the
errors in the workflow.
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription = ex.StackTrace;
}
}
In method onTaskChanged2_Invoked Delete all code and replace
by this segment code
private void
onTaskChanged2_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
this.onTaskChanged2_AfterProperties1 = this.onTaskChanged2.AfterProperties;
this.onTaskChanged2_BeforeProperties1 = this.onTaskChanged2.BeforeProperties;
//Set the PercentComplete property to 1.0
(i.e. 100%)
//to indicate that the task has been
completed.
this.onTaskChanged2_AfterProperties1.PercentComplete
= (float)1.0;
//Get the value of Remarks Column (InfoPath
Form) by using the ExtendedProperties property
//string remarks =
this.onTaskChanged2_BeforeProperties1.ExtendedProperties["Remarks"].ToString();
}
catch (Exception
ex)
{
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription = ex.StackTrace;
//throw ex;
}
}
In method ReviewFinished Delete all code and replace by this
segment code
private void ReviewFinished(object sender, ConditionalEventArgs
e)
{
try
{
if (this.onTaskChanged2_AfterProperties1.PercentComplete
== (float)1.0)
{
e.Result = true;
}
else
{
e.Result = false;
}
}
catch (Exception
ex)
{
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace,
System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription = ex.StackTrace;
}
}
/////////////////////////////////// All 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 StateMachineWorkflow.Workflow1
{
public sealed partial class Workflow1 : StateMachineWorkflowActivity
{
public Workflow1()
{
InitializeComponent();
}
public SPWorkflowActivationProperties
workflowProperties = new SPWorkflowActivationProperties();
public Guid
createTask1_TaskId1 = default(System.Guid);
public SPWorkflowTaskProperties
createTask1_TaskProperties1 = new
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
private void
createTask1_MethodInvoking(object sender, EventArgs e)
{
try
{
//Create a new TaskId for the Task
this.createTask1_TaskId1 = Guid.NewGuid();
//TaskProperties field is used to configure
the Task Details.
this.createTask1_TaskProperties1.Title =
"General Direct Manage Review";
//You can assign a Task to an user or to a
group.
//Here we assign the task to Direct manager
User
this.createTask1_TaskProperties1.AssignedTo
= "quochung-axioo\\Instructor";
//Task Type corresponds to TaskURN specified in
Elements.xml
this.createTask1_TaskProperties1.TaskType
= 1;
this.createTask1_TaskProperties1.DueDate
= DateTime.Today.AddDays(5.0);
}
catch (Exception
ex)
{
//Logging is used so that we can debug the
errors in the workflow.
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription = ex.StackTrace;
}
}
public SPWorkflowTaskProperties
onTaskChanged1_AfterProperties1 = new
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
public SPWorkflowTaskProperties
onTaskChanged1_BeforeProperties1 = new
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
private void
onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
this.onTaskChanged1_AfterProperties1 = this.onTaskChanged1.AfterProperties;
this.onTaskChanged1_BeforeProperties1 = this.onTaskChanged1.BeforeProperties;
//Set the PercentComplete property to 1.0
(i.e. 100%)
//to indicate that the task has been
completed.
this.onTaskChanged1_AfterProperties1.PercentComplete
= (float)1.0;
}
catch (Exception
ex)
{
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription = ex.StackTrace;
//throw ex;
}
}
private void
ReadyForReview(object sender, ConditionalEventArgs e)
{
try
{
if (this.onTaskChanged1_AfterProperties1.PercentComplete
== (float)1.0 )
//&&this.onTaskChanged1_AfterProperties1.
//ExtendedProperties["Status"].ToString().Contains("Approve")
{
e.Result = true;
}
else
{
e.Result = false;
}
}
catch (Exception
ex)
{
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription = ex.StackTrace;
}
}
public Guid
createReviewTask_TaskId1 = default(System.Guid);
public SPWorkflowTaskProperties
createReviewTask_TaskProperties1 = new
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
private void
createReviewTask_MethodInvoking(object sender, EventArgs e)
{
try
{
//Create a new TaskId for the Task
this.createReviewTask_TaskId1 = Guid.NewGuid();
//TaskProperties field is used to configure
the Task Details.
this.createReviewTask_TaskProperties1.Title
= "HR Manager Review";
//You can assign a Task to an user or to a
group. Here we assign the task to HR User
this.createReviewTask_TaskProperties1.AssignedTo
= "quochung-axioo\\Learner";
//Task Type corresponds to TaskURN specified
in Elements.xml
this.createReviewTask_TaskProperties1.TaskType
= 2;
this.createReviewTask_TaskProperties1.DueDate
= DateTime.Today.AddDays(2.0);
}
catch (Exception
ex)
{
//Logging is used so that we can debug the
errors in the workflow.
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription = ex.StackTrace;
}
}
public SPWorkflowTaskProperties
onTaskChanged2_AfterProperties1 = new
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
public SPWorkflowTaskProperties
onTaskChanged2_BeforeProperties1 = new
Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
private void
onTaskChanged2_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
this.onTaskChanged2_AfterProperties1 = this.onTaskChanged2.AfterProperties;
this.onTaskChanged2_BeforeProperties1 = this.onTaskChanged2.BeforeProperties;
//Set
the PercentComplete property to 1.0 (i.e. 100%)
//to indicate that the task has been
completed.
this.onTaskChanged2_AfterProperties1.PercentComplete
= (float)1.0;
//Get the value of Remarks Column (InfoPath
Form) by using the ExtendedProperties property
//string remarks =
this.onTaskChanged2_BeforeProperties1.ExtendedProperties["Remarks"].ToString();
}
catch (Exception
ex)
{
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription = ex.StackTrace;
//throw ex;
}
}
private void
ReviewFinished(object sender, ConditionalEventArgs e)
{
try
{
if (this.onTaskChanged2_AfterProperties1.PercentComplete
== (float)1.0)
{
e.Result = true;
}
else
{
e.Result = false;
}
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("mstechshareing.com Workflow",
ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
LogToHistoryListActivity log = new LogToHistoryListActivity();
log.HistoryDescription = ex.StackTrace;
}
}
}
}
/////////////////////////////////// End All Code ////////////////////////
Right click Workflow1 | Add new item | Module and provide
name is Forms
Delete Sample.txt file and right click Forms Add | Existing
Item (Image 10)
Expand Feature Receiver:
At Assembly paste code: Microsoft.Office.Workflow.Feature,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
<Property Key="RegisterForms" Value="Forms\*.xsn"/>
Step 1: Copy this segment code and paste to here
TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160"
<AssociationData>
<Data></Data>
</AssociationData>
<Task1_FormURN>urn:schemas-microsoft-com:office:infopath:GeneralDirectorAppovePublish:-myXSD-2012-03-23T08-37-10</Task1_FormURN>
<Task2_FormURN>urn:schemas-microsoft-com:office:infopath:HRManagerApprovePublish:-myXSD-2012-03-23T09-35-52</Task2_FormURN>
Deploy Project