ĐÀO TẠO DOANH NGHIỆP : SỞ KHOA HỌC CÔNG NGHỆ TỈNH ĐỒNG NAI

ENTERPRISE TRAINING: DONG NAI DEPARTMENT OF SCIENCE AND TECHNOLOGY.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

Sunday, March 25, 2012

SharePoint 2010 State Machine Workflows with Custom Task Forms (InfoPath) using Visual Studio 2010 (Part 3)


Download Only State machine Example as guide in State machine Article at here
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)

Right click to Workflow1 | Properties

Expand Feature Receiver:
At Assembly paste code: Microsoft.Office.Workflow.Feature, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
At Class Name Paste code: Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver

Right click Workflow1.cs | Properties

At Deployment Type: choose ElementFile

Right click Feature1.Template.xml | Open

Copy this segment code and paste to here

<Property Key="RegisterForms" Value="Forms\*.xsn"/>
Right click to Elements.xml  of Workflow1| Open

Step 1: Copy this segment code and paste to here

TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160"

Step 2: Copy this segment code and paste to here

<AssociationData>
    <Data></Data>
</AssociationData>

Step 3: Copy this segment code and paste to here (Image 20)

<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
Open your site | go to Shared Documents | upload document | workflow automatic run

Click to “In Progress” link

You see have a Task is assigned to Direct Manager

Click to Title

Input Approve to Status and comment

After Direct manager was Approved, auto create new task and assign to HR Manager

Click to Title of HR Manager

Input Status and comment as follows:

After Direct Manager and HR Manager were Approved => Status is Completed

Back to Shared documents you see your document is completed

Download Project and Infopath form after Finished Project 

SharePoint 2010 State Machine Workflows with Custom Task Forms (InfoPath) using Visual Studio 2010 (Part4)


How to Get data to Tasks List from Infopath Forms

Create new column is Comment (Single line of text) same name of Infopath Form
Field Status in Task List is exist
Open Shared Document and upload document then run workflow: Input Status and Comment as follows:
After Submit form infopath you see Status and Comment Field is updated same data is submitted from infopath
Continue, Task is assigned to User HR

Open Form and input as follows:
Data is saved in Task List

Thursday, March 22, 2012

How to Validation Column In Sharepoint 2010


How to Validation Coumn in sharepoint 2010
Create new Custom List LeaveForm
Create a new column StartDate (Date and Time)
Create a new column EndDate (Date and Time)
Go to List Setting | Validation settings
Set Formula as follows
Error when StartDate > EndDate as follows: