Saturday, March 12, 2011

Built-in Workflows Share Point 2010.

I found the following tutorial to use built-in workflows on office.microsoft.com.

Add a workflow to a list or library



  1. Browse to the list or library where you want to add the workflow.

  2. Click the List tab if it’s a list, or the Library tab if it’s a library.

  3. In the Settings group, click Workflow Settings.

  4. On the Workflow Settings page, click Add a workflow.


Add a workflow to a list or library content type



  1. Browse to the list or library containing an instance of the list content type you want to modify.

  2. Click the List tab if it’s a list, or the Library tab if it’s a library.

  3. Click List Settings if it’s a list or Library Settings if it’s a library.

  4. Under Content Types, click the name of the content type you want to associate the workflow with. If you don’t see Content Types on the page, you may need to choose Advanced Settings and then Allow management of content types.

  5. Under Settings, choose Workflow settings.

  6. Click Add a workflow.


Add a workflow to a site content type



  1. From the home page for the site collection, choose Site Actions and then Site Settings.

  2. Under Galleries, click Site content types.

  3. Click the name of the site content type you want to add or associate the workflow with.

  4. Click Workflow Settings.

  5. On the Workflow Settings page, click Add a workflow.


The Add a Workflow page

Performing any of the steps above brings you to the Add a Workflow page where you choose the type of workflow, name of workflow, task list to use, etc.

clip_image001

On this page, you can configure the following workflow settings:



  • Choose a workflow template, like Approval,

  • Specify a name for the workflow.

  • Specify the Task list to use for the tasks in this workflow.

  • Specify the History list to use for this workflow.

  • Allow the workflow to be manually started by users.

  • Require the Manage Lists Permissions to start the workflow.

  • Start the workflow to approve publishing a major version of an item.

  • Start the workflow when a new item is created.

  • Start the workflow when an item is changed.


The association form

The next page shows the workflow behaviors that you can change, like the approvers, workflow message, and due dates. The values you choose become the default values when users start the workflow – in other words, you fill out the association form exactly once, when you add the workflow to a list, library, or content type, and those values are used in all subsequent instances of the workflow.

The association form is different for each of the workflows included with SharePoint. This is what you see when associating Approval workflows.

clip_image002

On this page, you can specify the following workflow behaviors:



  • Approvers for the workflow.

  • Order of approvers: serial or parallel

  • Stages of approval.

  • Expand groups by assigning tasks to every member of the group.

  • Request message that appears in the workflow.

  • Due date for all tasks.

  • Duration per task.

  • Duration units: days, weeks, or months.

  • CC, who to carbon copy the assigned tasks.

  • End the workflow on first rejection.

  • End the workflow if the document changes.

  • Enable content approval by updating the approval status when the workflow completes.


Starting the workflow

Once the workflow has been associated with a list, library, or content type, you and others are ready to start using the workflow. If you chose to start the workflow when items are created or changed (on the Add a Workflow page), users won’t see a difference or even know a workflow has started when creating and updating documents or list items on the site. When these options are not selected, users start the workflow on their own, manually.

They do this by choosing the Workflows option from within the Office 2010 application used to create the document, or they can choose the Workflows options from the list or library where the item is stored, such as the pull-down menu beside the list item.

clip_image003

Clicking here, takes the user to the Start a New Workflow page, which shows the available workflows that can be started plus the status of other workflows that are running and have completed.

clip_image004

Lastly, they see the workflow initiation form where they can specify the core behaviors of the workflow. In contrast with the association form, which is completed exactly once when the workflow is first added to a list, library, or content type, the initiation form is completed once each time the workflow is started manually – so each instance of the workflow can use different initiation form values, but they all use the same association form values.

The form is different for each of the workflows included with SharePoint, and default values will appear in the form if they were added to the association form (as described earlier). The Approval workflow initiation form, without any default values, looks like this.

clip_image005

The person starting the workflow can add new values or leave the defaults and then choose Start. This creates a task and assigns it to the first approver listed.

Approving the workflow

For the approvers listed in the workflow, they receive a task assigned to them, and they receive an email notification. They can approve or reject the task directly from within certain Office 2010 applications, like Outlook – or they can go directly to the Tasks list, where they will see the new task assigned to them.

When they open the task, they see the task form that they can use to approve, reject, request a change, or reassign the task. The task form for the Approval workflow looks like this.

clip_image006

Depending on the approver’s actions, the task might be assigned to the next approver, sent back to the author with requested changes, or approved, which completes the workflow.

Develop Basic Approval Workflow Using Visual Studio2010 and Infopath2010.

In this exercise you will extend the previous workflow to implement the basic approval process using Visual studio2010 and Infopath2010.

1. Open (Last Post Project)in visual studio 2010:

clip_image002

2. In solution explorer expand Workflow1 and double click on Element.Xml file.

clip_image004

2. In the workflow definition file (Element.xml), set the TaskListContentTypeId attribute of the Workflow element to the following content type. This content type, included in Microsoft SharePoint Server 2010, specifies custom task display and edit forms that include an Office Forms Server control for rendering InfoPath forms.

TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160"  


clip_image005

3. Let us create task form using InfoPath 2010 through which an approver can approve and reject the request.

a. open InfoPath 2010 and select blank form in popular form templates then click design form button.

clip_image007

b. add title and controls from Home tab in ribbon as mentioned below.

clip_image009

c. right click on Fields pane on right side and select add then specify the field status as text.

clip_image011

clip_image012

d. In Data tab of ribbon select data connections and click add button.

clip_image014

clip_image016

e. select create new connection to submit data and click next button.

clip_image018

f. select to the hosting environment, such as an ASP.Net page or hosting application and click next .

clip_image020

g. Enter the name for data connection and then click Finish button.

clip_image022

a. Click close button.

clip_image024

I. Double Click on Approve button then on ribbon you will find Control Tools tab in this click on rules button.

clip_image026

j. Click Add button then select set field value clip_image028

k. Again click on Add button and then select SubmitData.

clip_image030

L. Again click on Add button and then select Close the form.

clip_image032

M. Repeat all steps from I-L for reject button but set status to rejected while setting a field status.

N. Double click on close Button click rules click on Add button select Close the form.

O. Save the form with the name ApproveReject2010.


Publish the form:
To publish the form click on file tab on ribbon then select publish.
clip_image034
Select Network location Option then click on browse button. Specify the following location in file name and click ok then on this location make a new folder with name Forms.C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\WorkFlowLab1_Feature1 this is the location where workflow is published.
clip_image036

Specify the name Of File =” ApproveReject2010.xsn” Click ok then click next.

clip_image038

Clear the textbox on next screen then click next then publish and close the form.

clip_image040

clip_image042

Now go to the location C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\WorkFlowLab1_Feature1\Forms right click on approvereject2010 file then click on design this will open the published form.

clip_image044

Now on file tab on ribbon select Info then in right pane click on Form template Properties.

clip_image046

Copy the text in Id.

clip_image048

Close the form and return to visual studio2010.

3. Add an element to the Metadata element of the workflow template definition. This element is TaskID_FormURN Element (Workflow), where N represents the integer you assigned to that task type within the workflow. Set this element to the URN of the InfoPath 2010 form you want to use with this task.

<Task0_FormURN>urn:schemas-microsoft-com:office:infopath:ApproveReject2010:-myXSD-2010-08-22T06-49-46</Task0_FormURN>

clip_image050

In solution Explorer Expand Feature1 then double click on Feature1.feature.

clip_image052

Click on manifest then click on edit options.

clip_image054

clip_image056

Add <Property Key="RegisterForms" Value="Forms\*.xsn" /> tag under Peroperties tag and Click on overwrite generated xml link.

clip_image058

clip_image060

Click on Edit in XML editor link then add following Tags.as mentioned in screen shot below.ReceiverAssembly="Microsoft.Office.Workflow.Feature, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" ReceiverClass="Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver"clip_image062

2. Setup the auto association parameters that will tell Visual Studio to automatically associate your workflow with the TestList when it is deployed.

a. Select Workflow1 in the solution explorer. clip_image064

b. In the Properties window, set the Auto Associate property to True.

c. In the History List property click the [...] button to start the wizard.

d. Click Next >, On the 2nd page select a list of Shared Documents in the first dropdown and click Next

clip_image066

e. On the final page check the first check box and clear the rest and click Finish.

Deploy the workflow to SharePoint and verify that it works.

f. Right click the project in solution explorer and click Deploy.

g. When the deployment is complete, open Internet Explorer and navigate to http://localhost/Shared%20Documents/Forms/AllItems.aspx.

Click on add Document link and then upload the document.

clip_image068

Click the drop down menu on the Expense Report in the list and select Workflows

clip_image070

Click the WorkFlowLab1-Workflow-1 link to start the workflow.

clip_image072

Click the In Progress link under WorkFlowLab1-Workflow-1 to track the workflow

clip_image074

Click on Task mentioned in Task List notice that task is associated with our custom content type defined by InfoPath ApproveReject from.

image

Task Assignment Using Workflows

In this exercise you will extend the previous workflow to implement the basic Task assignment process using Visual studio2010.

1. Open (Previous Post)in visual studio 2010:

clip_image002

2. Add a new CreateTaskActivity between onWorkflowActivated1 and logToHistoryListActivity1 from the SharePoint Workflow section of the toolbox.

clip_image004

3. Right Click on CreateTaskactivity Select Properties.

clip_image006

clip_image008

4. The first thing needed here is a correlation token for the task. A correlation token is used for message correlation in workflow. It provides a unique identifier that enables a mapping between a task object in a specific workflow instance and the workflow runtime in SharePoint. This is used so that when SharePoint receives a message for the workflow instance it can locate the correct task within the correct workflow instance. The CorrelationToken property must be configured and it’s not recommended to use the WorkflowToken for tasks, although this isn’t prevented in the tool. Enter the new name for the correlation token as TaskToken and press enter. Then expand the (+) symbol which appears and click the drop down to the right of OwnerActivityName and choose the workflow1.

clip_image009

5. The TaskId must be configured and a new GUID specified for the task id. This is done by selecting the TaskId property and clicking the […] ellipsis to bring up the property editor. Click the Bind to a new member tab, choose Create Field, and then click OK. The same must be done for the TaskProperties property by again selecting the property, clicking on the ellipsis and adding a new field.

clip_image011

clip_image013

6. Double click on the new CreateTask activity on the workflow design surface to bring up the createTask1_MethodInvoking handler code and set the properties in code.

clip_image014

7. Place the following code inside the createTask1_MethodInvoking method. The new task must be given a title, and for good measure. Specify user to whom task would be assigned, here we are assigning task to user who is initiating workflow.

{

createTask1_TaskId1 = Guid.NewGuid();

createTask1_TaskProperties1.Title = “MyTask ";

createTask1.TaskProperties.AssignedTo = workflowProperties.OriginatorUser.LoginName;

}

clip_image016

8. Add a new onTaskChanged1 following Createtask1Activity1 from the SharePoint Workflow section of the toolbox.

clip_image018

9. To configure the OnTaskChanged, you need to wire up the CorrelationToken and the TaskId properties to the same fields as the CreateTask1. This is done by selecting the TaskId property and clicking the […] ellipsis to bring up the property editor click bind to existing member and select Create_Task1_TaskId1 and click ok.

clip_image019

clip_image020

10. Add a new CompleteTask following Createtask1Activity1 from the SharePoint Workflow section of the toolbox.

clip_image022

11. To configure the OnTaskChanged, you need to wire up the CorrelationToken and the TaskId properties to the same fields as the CreateTask1. This is done by selecting the TaskId property and clicking the […] ellipsis to bring up the property editor click bind to existing member and select Create_Task1_TaskId1 and click ok.

clip_image019[1]

clip_image023

This is consistent throughout SharePoint workflow.

clip_image025

12. Deploy the workflow to SharePoint and verify that it works.

Ø Right click the project in solution explorer and click Deploy.

Ø When the deployment is complete, open Internet Explorer and navigate to http://servername/Lists/TestList/AllItems.aspx.

13. Click the drop down menu on one of the Item in the list and select Workflows.

clip_image027

14. Click the WorkFlowLab1-Workflow-1 link to start the workflow.

clip_image029

15. Click the In Progress link under WorkFlowLab1-Workflow-1 to track the workflow.

clip_image031

16. Click on Task mentioned in Task List notice task is assigned to work flow initiator.

clip_image033

17. Click on Edit Item.

clip_image035

18. Set Status = Completed and percentage to 100% then click Save button.

clip_image037

18. Notice that status of both task and workflows are set to Completed and history log activity that is last activity of workflow has been executed.so this is the end of Exercise-2 with successful task assignment workflow.

clip_image042