Workflow Engine NET Change Notice Application

Workflow Engine NET Change Notice Application

How to integrate a BPM Workflow Engine NET Change Notice with cDevWorkflow

This BPM Workflow Engine NET Change Notice demonstrates how to integrate a Change Notice application with cDevWorkflow using some of the key features of Business Process Management (BPM) workflow.

This Workflow Engine NET Change Notice will perform the following:

  1. Create a new Change Notice and submit for approval.
  2. View the newly created Change Notice.
  3. Using the workflow task, Approve or Reject the Change Notice.
  4. View the status of the Change Notice.

This sample will also focus on the following Change Notice Workflow points:

  • How to get a handle to a workflow definition
  • How to create a workflow instance from the workflow definition
  • How to execute the instance and also pass in startup variables values
  • How to get a list of tasks
  • How to get information from one task
  • How to render a task and form data
  • How to approve/reject a task using the cDevWorkflow API

Workflow Engine NET Change Notice Application Screens

Workflow Engine NET Change Notification workflow has the following screens. The first screen will display a list of Change Notices for the current user, and the screen looks as follows:

Workflow Engine NET Change Notice Tracking

Workflow Engine NET Change Notice Tracking

The next Workflow Engine NET Change Notice workflow screen lets you create a new Change Notice, and the screen looks as follows:

Workflow Engine NET Change Notice Create

Workflow Engine NET Change Notice Create

The last Workflow Engine NET Change Notice workflow screen shows workflow tasks for the current user, and the screen looks as follows:

Workflow Engine NET Change Notice View

Workflow Engine NET Change Notice View

In order to install the Workflow Engine NET Change Notice workflow sample, use the following documents to install and configure:

Source code explanations Default.aspx.cs

This page will render a list of Workflow Engine NET Change Notices from the database.  It’s a straight SQL call to the database to get the list and bind to the Gridview control.

 //get the list of CNs and display them on the table clsDataAccess oDA = new clsDataAccess(clsConfig.appConnectString); DataTable oDT = oDA.GetDataTable("SELECT * FROM cnData ORDER BY cnCreatedOn DESC"); gdvCns.DataSource = oDT; gdvCns.DataBind(); oDA.Disconnect(); 

New Change Notice.aspx.cs

New Change Notice screen let’s you create a new CN.  This screen also figures out the next maximum sequential number for the CN Number.  Once the new CN is created, it also gets a handle to the Change Notice workflow definition and creates an instance based on the definition.  New CN # is passed to the instance as a startup parameter and the instance starts execution.

//get the next CN number long lNextCNNumber = getNextCNNumber();
clsDataAccess oDA = new clsDataAccess(clsConfig.appConnectString);
string sSQL = string.Format("INSERT INTO cnData VALUES('{0}', '{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", Guid.NewGuid().ToString(), lNextCNNumber, txtName.Text, txtDesc.Text, "Submitted", DateTime.Now, clsConfig.workflowUserID, DateTime.Now, clsConfig.workflowUserID);
//insert a record into the CN table
if (oDA.NonQuery(sSQL))
{
txtName.Text = ""; txtDesc.Text = "";
//create a design object
deDesign oDesign = new deDesign(clsConfig.workflowConnectString, clsConfig.workflowUserID);
//get a handle to the workflow definition
deDefinition oDefinition = oDesign.getDefUsingName(clsConfig.cnDefinition);
//create a hashtable of input parameters
Hashtable oInParms = new Hashtable();
//pass the CN id to the workflow instance
oInParms["CNID"] = lNextCNNumber.ToString();
//create an instance from the definition
deInstance oInstance = oDefinition.createInstance(string.Format("CN{0}", lNextCNNumber));
bool bFlag = oInstance.execute(oInParms);
if (bFlag) { lblStatus.Text = string.Format("CN #: {0} created successfully and submitted to workflow...", lNextCNNumber);
}
else
{
lblStatus.Text = string.Format("CN #: {0} created successfully and failed to submit to workflow...", lNextCNNumber);
}
}
else
{
lblStatus.Text = "Failed to create the Change Notice"; } oDA.Disconnect();
}

MyTasks.aspx.cs

This page renders a list of tasks for the current user using the cDevWorkflow API.  List of tasks are bound to the Gridview table.

 //get a list of open tasks for the current user deRuntime oRuntime = new deRuntime(clsConfig.workflowConnectString, clsConfig.workflowUserID); DataTable oDT = oRuntime.getOpenTasks(); gdvTasks.DataSource = oDT; gdvTasks.DataBind(); 

ViewTask.aspx.cs

This renders the Change Notice workflow task information and information from the Change Notice.  The following code gets the details of the task:

 deRuntime oRuntime = new deRuntime(clsConfig.workflowConnectString, clsConfig.workflowUserID); //get the task information DataTable oDT = oRuntime.getTask(sTaskID); if (oDT != null &amp;&amp; oDT.Rows.Count &gt; 0) { //set the task information to the labels lblName.Text = oDT.Rows[0]["deTaskName"].ToString(); lblDesc.Text = oDT.Rows[0]["deTaskBody"].ToString(); lblExpDate.Text = oDT.Rows[0]["deTaskDueDate"].ToString(); sCNID = oDT.Rows[0]["deRoutedItem"].ToString(); }</div>
<div>

The next Change Notice workflow code fragment gets information about the Change Notice for rendering:

 //get the change notice information using the CN # clsDataAccess oDA = new clsDataAccess(clsConfig.appConnectString); oDT = oDA.GetDataTable(string.Format("SELECT * FROM cnData WHERE cnNumber='{0}'", sCNID)); if (oDT != null && oDT.Rows.Count > 0) { //set the CN information to the labels lblCNNumber.Text = oDT.Rows[0]["cnNumber"].ToString(); lblCNName.Text = oDT.Rows[0]["cnName"].ToString(); lblCNDesc.Text = oDT.Rows[0]["cnDescription"].ToString(); lblCNStatus.Text = oDT.Rows[0]["cnStatus"].ToString(); lblCNCreatedOn.Text = oDT.Rows[0]["cnCreatedOn"].ToString(); lblCNCreatedBy.Text = oDT.Rows[0]["cnCreatedBy"].ToString(); } oDA.Disconnect(); 

If the Change Notice workflow user approves the Change Notice, then the following code executes to approve and complete the task:

 //create a runtime object deRuntime oRuntime = new deRuntime(clsConfig.workflowConnectString, clsConfig.workflowUserID); //complete the task and set the task return value to completed if (oRuntime.completeTask(sTaskID, "completed", "")) { lblStatus.Text = "Change Notice has been approved"; btnApproveCN.Visible = false; btnRejectCN.Visible = false; } else { lblStatus.Text = "Error: cannot approve the Change Notice"; } 

If the user rejects the Change Notice, then the following code executes to reject and complete the task:

 //create a runtime object deRuntime oRuntime = new deRuntime(clsConfig.workflowConnectString, clsConfig.workflowUserID); //complete the task and set the task return value to rejected if (oRuntime.completeTask(sTaskID, "rejected", "")) { lblStatus.Text = "Change Notice has been rejected"; btnApproveCN.Visible = false; btnRejectCN.Visible = false; } else { lblStatus.Text = "Error: cannot reject the Change Notice"; } 

You may also be interested in reading more on the subject of Configuring a Custom Workflow Step.

A small sampling of the Workflow Technology for BPM Solutions contained within our cDevWorkflow product offering can be found here: Workflow Technology That Works.

Learn more about our Process Automation & IT, QA Services or Software Development products and solutions on the Web!  Visit us at: Innovative Process Solutions