Sunday, January 24, 2010

Statemachine Workflow

https://blogs.pointbridge.com/Blogs/morse_matt/Pages/Post.aspx?_ID=16

Feature.xml






Title="WSS StateMachine Workflow"
Description="This feature is a StateMachine workflow ..."
Version="12.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">







__________________________________________________________________
Workflow.xml








Name="Claims DMS StateMachine Workflow"
Description="This StateMachine workflow rocks..."
Id="8173FAC7-690E-4d1e-8CFC-DF6B492A7E8C"
CodeBesideClass="StateMachineDemo.DemoWorkflow"
CodeBesideAssembly="StateMachineDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ca4da04b1f46772a"
>






_____________________________________________________________________

StatemachineWorkflow.cs

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
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;
using System.Web.UI;
using System.Web;


namespace StateMachineDemo
{
#region DemoWorkflow
public sealed partial class DemoWorkflow : StateMachineWorkflowActivity
{
public DemoWorkflow()
{
InitializeComponent();
}

#region Declaration
public string _approver;
private bool _approved = false;
private bool _approvedFinal = false;
public string LastComments;
string taskStatus = string.Empty;
string workflowCurrentStatus = string.Empty;
string taskTitle = string.Empty;
string strHistoryURL = string.Empty;
string taskhiddenStatus = string.Empty;

List workflowTaskItems = new List();
Hashtable htTaskItems = new Hashtable();
DateTime dt = DateTime.Now;

string currentDateTime = DateTime.Now.ToString("dd/MM/yyyy");

public int DocitemId;
public int taskitemId;

public string taskPreviousState = string.Empty;
public string taskPreviousComments = string.Empty;
public string taskPreComments = string.Empty;


public String WorkFlowActivated_logToHistoryListActivity_HistoryDescription1 = default(System.String);
public Guid CreateTask_ReviewTask_TaskId1 = default(System.Guid);
public SPWorkflowTaskProperties CreateTask_ReviewTask_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

public Guid OnReviewTaskChanged_TaskId1 = default(System.Guid);
public SPWorkflowTaskProperties OnReviewTaskChanged_AfterProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
public SPWorkflowTaskProperties OnReviewTaskChanged_BeforeProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

public Guid CompleteReviewTask_TaskId1 = default(System.Guid);

public Guid CreateTask_CustReviewTask_TaskId1 = default(System.Guid);
public SPWorkflowTaskProperties CreateTask_CustReviewTask_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

public Guid OnCustReviewTaskChanged_TaskId1 = default(System.Guid);
public SPWorkflowTaskProperties OnCustReviewTaskChanged_AfterProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
public SPWorkflowTaskProperties OnCustReviewTaskChanged_BeforeProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

public Guid CompleteCustReviewTask_TaskId1 = default(System.Guid);
public Guid CreateTask_InProgressTask_TaskId1 = default(System.Guid);
public SPWorkflowTaskProperties CreateTask_InProgressTask_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

public Guid OnInProgressTaskChanged_TaskId1 = default(System.Guid);
public SPWorkflowTaskProperties OnInProgressTaskChanged_AfterProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
public SPWorkflowTaskProperties OnInProgressTaskChanged_BeforeProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

public String OnReviewTaskChanged_Executor1 = default(System.String);
public Int32 logToHistoryListActivity3_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity4_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity5_UserId2 = default(System.Int32);
public Int32 logToHistoryListActivity1_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity2_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity7_UserId1 = default(System.Int32);
public String OnCustReviewTaskChanged_Executor1 = default(System.String);
public Int32 logToHistoryListActivity9_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity10_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity11_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity6_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity8_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity12_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity14_UserId1 = default(System.Int32);
public Int32 logToHistoryListActivity15_UserId1 = default(System.Int32);

public Int32 logToHistoryListActivity13_UserId1 = default(System.Int32);
public String OnInProgressTaskChanged_Executor1 = default(System.String);

public Int32 WorkFlowActivated_logToHistoryListActivity_UserId1 = default(System.Int32);

public Guid completeTask1_TaskId1 = default(System.Guid);

private const int TaskType_InProgress = 0;

private const int TaskType_Review = 1;

private const int TaskType_Customer = 2;

public SPWorkflowActivationProperties workflowProperties = new Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties();
#endregion

#region OnWorkflowActivated_Invoked
///
/// On Work Flow Activated Task will be created to GOSSPL Technical Team
///

///
///
private void OnWorkflowActivated_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
_approver = @"GOSSPL Technician Team";
workflowCurrentStatus = "In Progress";
taskPreviousState = "";
LastComments = "Claims Work Flow has Initiated by Claims Team!";

SPWeb thisWeb = new SPSite(workflowProperties.SiteId).OpenWeb(workflowProperties.WebId);
SPListItem thisDocitemId = thisWeb.Lists[workflowProperties.ListId].GetItemById(workflowProperties.ItemId);
DocitemId = thisDocitemId.ID;
//taskitemId = 0;
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow OnWorkflowActivated_Invoked Method";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}

}
#endregion

#region Creating Task To GOSSPL Technical Team
private void CreateTask_ReviewTask_Invoked(object sender, EventArgs e)
{
string strTemp = string.Empty;
try
{

CreateTask_ReviewTask_TaskId1 = Guid.NewGuid();
if (taskPreviousState == "In Progress")
{
CreateTask_ReviewTask_TaskProperties1.Title = TaskTitle("R", "In Progress");

}
else if (taskPreviousState == "Rejected")
{
CreateTask_ReviewTask_TaskProperties1.Title = TaskTitle("A", "Rejected");
}
else if (taskPreviousState == "Quality Check")
{
CreateTask_ReviewTask_TaskProperties1.Title = TaskTitle("R", "In Progress");
}
else
{
CreateTask_ReviewTask_TaskProperties1.Title = TaskTitle("A", "In Progress");
}
if (htTaskItems.Count != 0)
{
CopyTaskProperties(CreateTask_ReviewTask_TaskProperties1);
}
CreateTask_ReviewTask_TaskProperties1.AssignedTo = @"GOSSPL Technician Team";

//************************************
//CreateTask_InProgressTask_TaskProperties1.ExtendedProperties["Task Groups"] = @"GOSSPL Technician Team";
//SPGroup group = SPWeb.UserGroups[];
//SPGroup group = SPWeb.
//SPFieldUserValue groupvalue = new SPFIeldUserValue(group.ParentWeb, group.ID, group.Name);
//SPWorkflowTaskProperties taskProperties = new SPWorkflowTaskProperties();

//taskProperties.AssignedTo = groupvalue.LookupValue;

SPSite siteCollection = new SPSite("http://igtewfl2018/claims");
SPWeb rootWeb = siteCollection.OpenWeb();
SPGroup spGroup = rootWeb.Groups["GOSSPL Technician Team"];

SPFieldUserValue groupvalue = new SPFieldUserValue(spGroup.ParentWeb, spGroup.ID, spGroup.Name);

//SPFieldUserValue groupvalue = new SPFIeldUserValue(spGroup.ParentWeb, spGroup.ID, spGroup.Name);

CreateTask_ReviewTask_TaskProperties1.ExtendedProperties["Task Groups"] = groupvalue.LookupValue; ;
//********************************************
CreateTask_ReviewTask_TaskProperties1.Description = LastComments;
CreateTask_ReviewTask_TaskProperties1.DueDate = DateTime.Today.AddDays(2);

CreateTask_ReviewTask_TaskProperties1.ExtendedProperties["DocumentId"] = DocitemId;

strHistoryURL = workflowProperties.WebUrl + "/Lists/Tasks/TaskHistory.aspx?DocId=" + DocitemId;
CreateTask_ReviewTask_TaskProperties1.ExtendedProperties["History View"] = strHistoryURL + ", View History";

strHistoryURL = workflowProperties.WebUrl + "/Lists/Tasks/EditForm.aspx?ID=" + CreateTask_ReviewTask_TaskProperties1.TaskItemId + "&DocId=" + DocitemId + "&&Source=" + workflowProperties.WebUrl;
CreateTask_ReviewTask_TaskProperties1.ExtendedProperties["Task Edit"] = strHistoryURL + ", Edit";

CreateTask_ReviewTask_TaskProperties1.ExtendedProperties["Previous Comments"] = taskPreComments;
CreateTask_ReviewTask_TaskProperties1.ExtendedProperties["Processing Status"] = workflowCurrentStatus;

SetProperties(workflowProperties, CreateTask_ReviewTask_TaskProperties1);

}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow CreateTask_ReviewTask_Invoked Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}

}
#endregion

#region GOSSPL Technical Team Task Change
private void OnReviewTaskChanged_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
taskStatus = string.Empty;
string OverallStatus = workflowProperties.Item["Processing Status"].ToString();
Guid ststusFieldId = workflowProperties.TaskList.Fields["Task Status"].Id;
Guid assignedToId = workflowProperties.TaskList.Fields["Assigned To"].Id;
taskStatus = OnReviewTaskChanged_AfterProperties1.ExtendedProperties[ststusFieldId].ToString();

Guid approverComment = workflowProperties.TaskList.Fields["Comment"].Id;
taskPreviousComments = OnReviewTaskChanged_AfterProperties1.ExtendedProperties[approverComment].ToString();


if (htTaskItems.Count > 0) htTaskItems.Clear();

UpdateTaskProperties(workflowProperties, OnReviewTaskChanged_AfterProperties1);

if (taskStatus != null)
{
if (taskStatus == "Approved")
{
_approved = false;
workflowProperties.Item["Processing Status"] = "Quality Check";
workflowProperties.Item.Update();
workflowCurrentStatus = "Quality Check";
taskPreviousState = "In Progress";

}
else if (taskStatus == "Rejected")
{
_approved = true;
workflowProperties.Item["Processing Status"] = "Rejected";
workflowProperties.Item.Update();
workflowCurrentStatus = "Rejected";
taskPreviousState = "In Progress";
}
}
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow OnReviewTaskChanged_Invoked Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region Creating Task To GOSSPL Quality Check Team
private void CreateTask_CustReviewTask_MethodInvoking(object sender, EventArgs e)
{
try
{
CreateTask_CustReviewTask_TaskId1 = Guid.NewGuid();
if (taskPreviousState == "In Progress")
{
CreateTask_CustReviewTask_TaskProperties1.Title = TaskTitle("A", "Quality Check");
}
else
{
CreateTask_CustReviewTask_TaskProperties1.Title = TaskTitle("R", "Quality Check");
}

CopyTaskProperties(CreateTask_CustReviewTask_TaskProperties1);
CreateTask_CustReviewTask_TaskProperties1.AssignedTo = @"GOSSPL Quality Check Team";
CreateTask_CustReviewTask_TaskProperties1.ExtendedProperties["Processing Status"] = workflowCurrentStatus;
CreateTask_CustReviewTask_TaskProperties1.ExtendedProperties["DocumentId"] = DocitemId;
CreateTask_CustReviewTask_TaskProperties1.DueDate = DateTime.Today.AddDays(2);

strHistoryURL = workflowProperties.WebUrl + "/Lists/Tasks/TaskHistory.aspx?DocId=" + DocitemId;
CreateTask_CustReviewTask_TaskProperties1.ExtendedProperties["History View"] = strHistoryURL + ", View History";

strHistoryURL = workflowProperties.WebUrl + "/Lists/Tasks/EditForm.aspx?ID=" + CreateTask_CustReviewTask_TaskProperties1.TaskItemId + "&DocId=" + DocitemId + "&&Source=" + workflowProperties.WebUrl;
CreateTask_CustReviewTask_TaskProperties1.ExtendedProperties["Task Edit"] = strHistoryURL + ", Edit";
CreateTask_CustReviewTask_TaskProperties1.ExtendedProperties["Previous Comments"] = taskPreComments;

CreateTask_CustReviewTask_TaskProperties1.TaskType = TaskType_Customer;

SetProperties(workflowProperties, CreateTask_CustReviewTask_TaskProperties1);
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow CreateTask_CustReviewTask_MethodInvoking Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region GOSSPL Quality Check Team Task Change
private void OnCustReviewTaskChanged_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
taskStatus = string.Empty;
string OverallStatus = workflowProperties.Item["Processing Status"].ToString();
Guid ststusFieldId = workflowProperties.TaskList.Fields["Task Status"].Id;
Guid assignedToId = workflowProperties.TaskList.Fields["Assigned To"].Id;
taskStatus = OnCustReviewTaskChanged_AfterProperties1.ExtendedProperties[ststusFieldId].ToString();

Guid approverComment = workflowProperties.TaskList.Fields["Comment"].Id;
taskPreviousComments = OnCustReviewTaskChanged_AfterProperties1.ExtendedProperties[approverComment].ToString();
if (htTaskItems.Count > 0) htTaskItems.Clear();
UpdateTaskProperties(workflowProperties, OnCustReviewTaskChanged_AfterProperties1);

if (taskStatus != null)
{
if (taskStatus == "Approved")
{
_approved = true;
workflowProperties.Item["Processing Status"] = "Completed";
workflowProperties.Item.Update();
workflowCurrentStatus = "Completed";
taskPreviousState = "Quality Check";
}
else if (taskStatus == "Rejected")
{
_approved = false;
workflowProperties.Item["Processing Status"] = "In Progress";
workflowProperties.Item.Update();
workflowCurrentStatus = "In Progress";
taskPreviousState = "Quality Check";
}
}
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow OnCustReviewTaskChanged_Invoked Method";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region Creating Task To Claims Team
private void CreateTask_InProgressTask_MethodInvoking(object sender, EventArgs e)
{
try
{
CreateTask_InProgressTask_TaskId1 = Guid.NewGuid();

if (taskPreviousState == "Quality Check")
{
CreateTask_InProgressTask_TaskProperties1.Title = TaskTitle("A", "Completed");
}
if (taskPreviousState == "In Progress")
{
CreateTask_InProgressTask_TaskProperties1.Title = TaskTitle("R", "Rejected");
}
if (taskPreviousState == "Completed")
{
CreateTask_InProgressTask_TaskProperties1.Title = TaskTitle("A", "Closed");
}

CopyTaskProperties(CreateTask_InProgressTask_TaskProperties1);

CreateTask_InProgressTask_TaskProperties1.AssignedTo = workflowProperties.OriginatorUser.LoginName.ToString();
CreateTask_InProgressTask_TaskProperties1.ExtendedProperties["Processing Status"] = workflowCurrentStatus;

CreateTask_InProgressTask_TaskProperties1.Description = LastComments;
CreateTask_InProgressTask_TaskProperties1.ExtendedProperties["DocumentId"] = DocitemId;

strHistoryURL = workflowProperties.WebUrl + "/Lists/Tasks/TaskHistory.aspx?DocId=" + DocitemId;
CreateTask_InProgressTask_TaskProperties1.ExtendedProperties["History View"] = strHistoryURL + ", View History";


strHistoryURL = workflowProperties.WebUrl + "/Lists/Tasks/EditForm.aspx?ID=" + CreateTask_InProgressTask_TaskProperties1.TaskItemId + "&DocId=" + DocitemId + "&&Source=" + workflowProperties.WebUrl; // TaskItemId not fecthing
CreateTask_InProgressTask_TaskProperties1.ExtendedProperties["Task Edit"] = strHistoryURL + ", Edit";

CreateTask_InProgressTask_TaskProperties1.DueDate = DateTime.Today.AddDays(2);
CreateTask_InProgressTask_TaskProperties1.ExtendedProperties["Previous Comments"] = taskPreComments;

CreateTask_InProgressTask_TaskProperties1.TaskType = TaskType_Review;
SetProperties(workflowProperties, CreateTask_InProgressTask_TaskProperties1);
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow CreateTask_InProgressTask_MethodInvoking Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region Claims Team Task Change
private void OnInProgressTaskChanged_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
taskhiddenStatus = string.Empty;
taskStatus = string.Empty;
string OverallStatus = workflowProperties.Item["Processing Status"].ToString();
Guid ststusFieldId = workflowProperties.TaskList.Fields["Task Status"].Id;
Guid assignedToId = workflowProperties.TaskList.Fields["Assigned To"].Id;
taskStatus = OnInProgressTaskChanged_AfterProperties1.ExtendedProperties[ststusFieldId].ToString();


Guid approverComment = workflowProperties.TaskList.Fields["Comment"].Id;
taskPreviousComments = OnInProgressTaskChanged_AfterProperties1.ExtendedProperties[approverComment].ToString();

if (htTaskItems.Count > 0) htTaskItems.Clear();
UpdateTaskProperties(workflowProperties, OnInProgressTaskChanged_AfterProperties1);

if (taskStatus != null)
{
if (taskStatus == "Approved" & workflowCurrentStatus == "Completed")
{
_approved = true;
workflowProperties.Item["Processing Status"] = "Closed";
workflowProperties.Item.Update();
workflowCurrentStatus = "Closed";
taskPreviousState = "Completed";
_approvedFinal = true;

}
else if (taskStatus == "Rejected" & workflowCurrentStatus == "Completed")
{
_approved = false;
_approvedFinal = true;
workflowProperties.Item["Processing Status"] = "Quality Check";
workflowProperties.Item.Update();
workflowCurrentStatus = "Quality Check";
taskPreviousState = "Completed";
}
if (taskStatus == "Approved" & workflowCurrentStatus == "Rejected")
{
_approved = true;
_approvedFinal = false;
workflowProperties.Item["Processing Status"] = "In Progress";
workflowProperties.Item.Update();
workflowCurrentStatus = "In Progress";
taskPreviousState = "Rejected";
}
if (taskStatus == "Rejected" & workflowCurrentStatus == "Rejected")
{
_approved = false;
_approvedFinal = false;
workflowProperties.Item["Processing Status"] = "Closed";
workflowProperties.Item.Update();
workflowCurrentStatus = "Closed";
taskPreviousState = "Rejected";
}
}
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow OnInProgressTaskChanged_Invoked Method";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region SetProperties
public void SetProperties(SPWorkflowActivationProperties wfProperties, SPWorkflowTaskProperties taskProperties)
{
try
{
string strTemp = string.Empty;
if (wfProperties.Item["UCR Number"] != null)
{
taskProperties.ExtendedProperties["UCR Number"] = wfProperties.Item["UCR Number"].ToString();
}
if (wfProperties.Item["Risk Number"] != null)
{
taskProperties.ExtendedProperties["Risk Number"] = wfProperties.Item["Risk Number"].ToString();
}
if (wfProperties.Item["Urgent"] != null)
{
if (wfProperties.Item["Urgent"].ToString().ToUpper() == "TRUE")
{
taskProperties.ExtendedProperties["Priority"] = "High";
}
}

if (wfProperties.Item["Standard Narrative"] != null)
{
strTemp = wfProperties.Item["Standard Narrative"].ToString();
if (strTemp == "First Advice - Regular" || strTemp == "First Advice and authority to appoint expert" || strTemp == "First Advice, expert appointed, await report")
{
taskProperties.ExtendedProperties["First Advice"] = "True";
}
if (strTemp == "First Advice - Regular" || strTemp == "First Advice and authority to appoint expert" || strTemp == "First Advice, expert appointed, await report" || strTemp == "Interim Settlement" || strTemp == "Final Settlement and Closure")
{
taskProperties.ExtendedProperties["Further Advice"] = "True";
}
if (strTemp == "Interim Settlement" || strTemp == "Final Settlement and Closure")
{
taskProperties.ExtendedProperties["Settlement"] = "True";
}
}
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow SetProperties Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region GetUserObject
private SPUser GetUserObject(string accountID)
{
try
{
if (accountID.IndexOf(@"\") > 0)
{
SPUser user = this.workflowProperties.Web.SiteUsers[accountID];
return user;
}
else
{
//replace DOMAIN
SPUser user = this.workflowProperties.Web.SiteUsers[@"DOMAIN\" + accountID];
return user;
}
}
catch
{
//replace DOMAIN and administrator
SPUser adminUser = this.workflowProperties.Web.SiteUsers[@"DOMAIN\administrator"];
return adminUser;
}
}
#endregion

#region UpdateTaskProperties
public void UpdateTaskProperties(SPWorkflowActivationProperties wfProperties, SPWorkflowTaskProperties taskProperties)
{
try
{
htTaskItems.Add("UK Rejection Reason", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["UK Rejection Reason"].Id]);
htTaskItems.Add(" Date Post Received", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields[" Date Post Received"].Id]);
htTaskItems.Add("Business Unit", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["Business Unit"].Id]);
//htTaskItems.Add("ECF", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["ECF"].Id]);
htTaskItems.Add("File Track Number", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["File Track Number"].Id]);
htTaskItems.Add("Insured/Reinsured/Coverholder", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["Insured/Reinsured/Coverholder"].Id]);
//GOSSPL rejection reason
htTaskItems.Add("GOSSPL Rejection Reason", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["GOSSPL Rejection Reason"].Id]);
htTaskItems.Add("UK Technician", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["UK Technician"].Id]);
htTaskItems.Add("Settlement", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["Settlement"].Id]);
htTaskItems.Add("Start Date", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["Start Date"].Id]);
//htTaskItems.Add("Due Date", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["Due Date"].Id]);
//htTaskItems.Add("% Complete", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["% Complete"].Id]);
htTaskItems.Add("Further Advice", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["Further Advice"].Id]);
htTaskItems.Add("First Advice", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["First Advice"].Id]);
//htTaskItems.Add("Priority", taskProperties.ExtendedProperties[wfProperties.TaskList.Fields["Priority"].Id]);
if (taskPreviousComments.Replace("
", "").Replace("
", "") != "")
{
taskPreComments = taskProperties.AssignedTo.ToString() + " " + DateTime.Now.ToString("dd/MM/yyyy") + " " + DateTime.Now.ToShortTimeString().ToString() + " : " + taskPreviousComments + "\n" + taskPreComments;
}
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow UpdateTaskProperties Method";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}

}
#endregion

#region CopyTaskProperties
public void CopyTaskProperties(SPWorkflowTaskProperties taskProperties)
{
try
{
taskProperties.ExtendedProperties["UK Rejection Reason"] = htTaskItems["UK Rejection Reason"];
taskProperties.ExtendedProperties[" Date Post Received"] = htTaskItems[" Date Post Received"];
taskProperties.ExtendedProperties["Business Unit"] = htTaskItems["Business Unit"];
//taskProperties.ExtendedProperties["ECF"] = htTaskItems["ECF"];
taskProperties.ExtendedProperties["File Track Number"] = htTaskItems["File Track Number"];
taskProperties.ExtendedProperties["Insured/Reinsured/Coverholder"] = htTaskItems["Insured/Reinsured/Coverholder"];
taskProperties.ExtendedProperties["GOSSPL Rejection Reason"] = htTaskItems["GOSSPL Rejection Reason"];
taskProperties.ExtendedProperties["UK Technician"] = htTaskItems["UK Technician"];
//taskProperties.ExtendedProperties["Rejection Reason"] = htTaskItems["Rejection Reason"];
taskProperties.ExtendedProperties["Settlement"] = htTaskItems["Settlement"];
taskProperties.ExtendedProperties["Start Date"] = htTaskItems["Start Date"];
//taskProperties.ExtendedProperties["Due Date"] = htTaskItems["Due Date"];
//taskProperties.ExtendedProperties["% Complete"] = htTaskItems["% Complete"];
taskProperties.ExtendedProperties["Further Advice"] = htTaskItems["Further Advice"];
taskProperties.ExtendedProperties["First Advice"] = htTaskItems["First Advice"];
//taskProperties.ExtendedProperties["Priority"] = htTaskItems["Priority"];


}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow CopyTaskProperties Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region ProposalApproved
private void ProposalApproved(object sender, ConditionalEventArgs e)
{
try
{
if (taskStatus != string.Empty && taskStatus != "" && taskStatus != null)
{
e.Result = _approved;
}
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow ProposalApproved Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region CompleteTask
private void CompleteTask(object sender, EventArgs e)
{
_approved = false;
}
#endregion

#region HandleException
public void HandleException(string strTrace, string strMessage, string strLocation)
{
try
{
SPWeb MyWeb = workflowProperties.Web;
MyWeb.AllowUnsafeUpdates = true;
SPList listException = MyWeb.Lists["N__CL_Exception"];
SPListItemCollection itemColException = listException.Items;
SPListItem itemException = itemColException.Add();
itemException["Title"] = strMessage;
itemException["Location"] = strLocation;
itemException["Description"] = strTrace;
itemException.Update();
}
catch (Exception)
{

}
}
#endregion

#region MyException
public class MyException : Exception
{
public MyException()
{
Console.WriteLine("User Defined Exception");
}
}
#endregion

#region Task Updates
public string TaskTitle(string taskType, string taskStatus)
{
string taskTitleDescription = string.Empty;
if (taskType == "A") // Title New or Approved case
{
switch (taskStatus)
{
case "In Progress":
taskTitleDescription = "A new claims is Initatied:" + workflowProperties.Item.File.Name.ToString();
break;
case "Rejected":
taskTitleDescription = "Claims is sent for Technician:" + workflowProperties.Item.File.Name.ToString();
break;
case "Quality Check":
taskTitleDescription = "Claims is sent for Quality Check:" + workflowProperties.Item.File.Name.ToString();
break;
case "Completed":
//taskTitleDescription = "Claims is sent for Completed:" + workflowProperties.Item.File.Name.ToString();
taskTitleDescription = "Task Ready for Closing assigned to you:" + workflowProperties.Item.File.Name.ToString();
break;
case "Closed":
taskTitleDescription = "Claims is Closed:" + workflowProperties.Item.File.Name.ToString();
break;
}
}
if (taskType == "R") // Title Old or Rejected case
{
switch (taskStatus)
{
case "In Progress":
//taskTitleDescription = "Claims Rejected by Technical Team!:" + workflowProperties.Item.File.Name.ToString();
taskTitleDescription = "Rejected Task assigned to you by Quality check Team!:" + workflowProperties.Item.File.Name.ToString();
break;
case "Quality Check":
taskTitleDescription = "Rejected Task assigned to you by Claims Team!:" + workflowProperties.Item.File.Name.ToString();
break;
case "Rejected":
taskTitleDescription = "Rejected Task assigned to you by Technician Team!:" + workflowProperties.Item.File.Name.ToString();
break;
}
}
return taskTitleDescription;
}
#endregion

#region Claims Approval Condition
private void Proposal2(object sender, ConditionalEventArgs e)
{
try
{
e.Result = _approvedFinal;
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow ProposalApproved Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region GetOriginator
private void GetOriginator(object sender, EventArgs e)
{
try
{
SPUser executor = GetUserObject(workflowProperties.Originator);
WorkFlowActivated_logToHistoryListActivity_UserId1 = executor.ID;
logToHistoryListActivity14_UserId1 = executor.ID;
logToHistoryListActivity15_UserId1 = executor.ID;
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow GetOriginator Method";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region GetOriginatorForTechTeam
private void GetOriginatorForTechTeam(object sender, EventArgs e)
{
try
{
if ((taskStatus == "Approved") || (taskStatus == string.Empty))
{
SPUser executor = GetUserObject(workflowProperties.Originator);
logToHistoryListActivity1_UserId1 = executor.ID;
logToHistoryListActivity2_UserId1 = executor.ID;
}
if (taskStatus == "Rejected")
{
SPUser executor = GetUserObject(OnCustReviewTaskChanged_Executor1);
logToHistoryListActivity1_UserId1 = executor.ID;
logToHistoryListActivity2_UserId1 = executor.ID;
}

}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow GetOriginatorForTechTeam Method";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region GetUserIDForTechChange
private void GetUserIDForTechChange(object sender, EventArgs e)
{
try
{
SPUser executor = GetUserObject(OnReviewTaskChanged_Executor1);
logToHistoryListActivity3_UserId1 = executor.ID;
logToHistoryListActivity4_UserId1 = executor.ID;
logToHistoryListActivity5_UserId2 = executor.ID;

}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow GetUserID Method";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}

}
#endregion

#region GetOriginatorForQualityTeam
private void GetOriginatorForQualityTeam(object sender, EventArgs e)
{
try
{
if (taskStatus == "Approved")
{
SPUser executor = GetUserObject(OnReviewTaskChanged_Executor1);
logToHistoryListActivity7_UserId1 = executor.ID;
logToHistoryListActivity12_UserId1 = executor.ID;
}
if (taskStatus == "Rejected")
{
SPUser executor = GetUserObject(OnInProgressTaskChanged_Executor1);
logToHistoryListActivity7_UserId1 = executor.ID;
logToHistoryListActivity12_UserId1 = executor.ID;
}


}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow GetOriginatorForQualityTeam Method";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region GetUserIdForQualityChange
private void GetUserIdForQualityChange(object sender, EventArgs e)
{
try
{
SPUser executor = GetUserObject(OnCustReviewTaskChanged_Executor1);
logToHistoryListActivity9_UserId1 = executor.ID;
logToHistoryListActivity10_UserId1 = executor.ID;
logToHistoryListActivity11_UserId1 = executor.ID;

}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow GetOriginatorForQualityTeam Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region GetOriginatorForClaims
private void GetOriginatorForClaims(object sender, EventArgs e)
{
try
{
if (taskStatus == "Approved")
{
SPUser executor = GetUserObject(OnCustReviewTaskChanged_Executor1);
logToHistoryListActivity6_UserId1 = executor.ID;
logToHistoryListActivity8_UserId1 = executor.ID;
}
if (taskStatus == "Rejected")
{
SPUser executor = GetUserObject(OnReviewTaskChanged_Executor1);
logToHistoryListActivity6_UserId1 = executor.ID;
logToHistoryListActivity8_UserId1 = executor.ID;
}

}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow GetOriginatorForClaims Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion

#region GetUserIdForClaimsChange
private void GetUserIdForClaimsChange(object sender, EventArgs e)
{
try
{
SPUser executor = GetUserObject(OnInProgressTaskChanged_Executor1);
logToHistoryListActivity13_UserId1 = executor.ID;
}
catch (Exception ex)
{
string strTrace = ex.StackTrace.ToString();
string strMessage = ex.Message.ToString();
string strLocation = "Statemachine Workflow GetOriginatorForClaims Method ";
HandleException(strTrace, strMessage, strLocation);
throw new MyException();
}
}
#endregion
}
#endregion
}

______________________________________________________________________________

Install.bat

:: Before running this file, sign the assembly in Project properties
::
:: To customize this file, find and replace
:: a) "StateMachineDemo" with your own feature names
:: b) "feature.xml" with the name of your feature.xml file
:: c) "workflow.xml" with the name of your workflow.xml file
:: d) "http://localhost" with the name of the site you wish to publish to

echo Copying the feature...

rd /s /q "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\StateMachineDemo"
mkdir "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\StateMachineDemo"

copy /Y feature.xml "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\StateMachineDemo\"
copy /Y workflow.xml "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\StateMachineDemo\"
xcopy /s /Y *.aspx "%programfiles%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS"

echo Adding assemblies to the GAC...

"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf StateMachineDemo
"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if bin\Debug\StateMachineDemo.dll




echo Activating the feature...

pushd %programfiles%\common files\microsoft shared\web server extensions\12\bin

::Note: Uncomment these lines if you've modified your deployment xml files or IP forms
stsadm -o deactivatefeature -filename StateMachineDemo\feature.xml -url http://igtewfl2018
stsadm -o uninstallfeature -filename StateMachineDemo\feature.xml

stsadm -o installfeature -filename StateMachineDemo\feature.xml -force
stsadm -o activatefeature -filename StateMachineDemo\feature.xml -url http://igtewfl2018

echo Doing an iisreset...
popd
iisreset

3 comments:

Anand Chandawarkar said...

Hi Naveen,

I seem to have a peculiar issue. I use "Form A.xsn" to kick-off the workflow (published to a form library). I have made copies of "Form A.xsn" such as "Form_A_Task.xsn" to be used as custom task edit forms (these forms contain ItemMetadata.xml file as secondary dataconnection). On the Createtask I am able to see the the data passed from "Form A" that the end user might have used to kick off the workflow. However, The reviewer when he ammends any data field values on the task form "Form_A_Task.xsn", I am not able to see those updated values in onTaskChanged activity using onTaskChanged.AfterProperties.ExtendedProperties[""].ToString();



Could anyone please help me out with this one.



Thanks & Regards,

Anand

PrashanthSpark said...

This is cool:)

Freddie M. Vang said...

Professional expertise is necessary for dealing with equipment that runs on gas. Get professional boiler repairs and find gas safe engineer and commercial catering engineers at Heating Engineer Leicester.

More details at: boiler service leicester .