IT tutorials
 
Technology
 

Developing Workflow Applications for Sharepoint 2013 (part 3) - Workflow and Visual Studio

10/11/2013 9:17:06 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

5. Workflow in Apps for SharePoint

For developers building Apps for SharePoint, whether SharePoint-hosted, Provider-hosted, or Autohosted, Visual Studio provides the tooling for including SharePoint workflows as a part of your solution. Therefore, you can augment your Apps for SharePoint with the workflow capabilities to encapsulate the business processes you want to deliver with your solutions.

In this Try It Out you learn to include a workflow in your app for SharePoint that shows a pattern for an expense approval workflow structure.


App for SharePoint with a Workflow (C15WFAppForSP.zip)

This exercise uses Office 365 but you can use your test on-premises SharePoint setup as well.
1. Run Visual Studio 2012 as Administrator. Select New Project.
2. In the New Project dialog, expand the Templates ⇒ Visual C# ⇒ Office/SharePoint ⇒ Apps nodes. Select App for SharePoint 2013 and provide the name C15WFAppForSP. Click OK.
3. In the Specify the app for SharePoint dialog, set the SharePoint site URL to which you will deploy the app, and choose SharePoint-hosted as the host for your App for SharePoint. Click Finish.
4. In the Solution Explorer, right-click the project node, and select Add ⇒ New item. In the Add New Item dialog, select Site Column, name it Manager, and click Add.
5. In the Solution Explorer, right-click the project node, and select Add ⇒ New item. In the Add New Item dialog, select Site Column, name it Disposition, and click Add.
6. In the Solution Explorer, right-click the project node, and select Add ⇒ New item. In the Add New Item dialog, select Site Column, name it EmpNum, and click Add.
7. Open the Elements.xml file for EmpNum and modify the following two attributes as follows:
Type="Integer"
Required="TRUE"
8. In the Solution Explorer, right-click the project node, and select Add ⇒ New item. In the Add New Item dialog, select Site Column, name it ExpenseAmount, and click Add.
9. Open the Elements.xml file for ExpenseAmount and modify the following two attributes as follows:
Type="Number"
Required="TRUE"
10. In the Solution Explorer, right-click the project node, and select Add ⇒ New item. In the Add New Item dialog, select List, name it ListToHostWorkflow, and click Add.
11. In the Choose List Settings dialog, leave the defaults, and click Finish.
12. In the List Designer, click Title, and type Expense Description. Leave it marked as required.
13. Additionally, in the List Designer, add the columns Emp Num and Expense Amount (make these required), and add Disposition and Manager (these two are not marked required; your workflow will populate these with values).
14. In Solution Explorer, expand the Pages node, and double-click the Default.aspx to open it. Add the following after the current <p>...</p> element on the page and prior to the </div> tag:
<p>
<a href="../Lists/ListToHostWorkflow"> 1) Create an expense
approval item in the List To Host Workflow</a>
</p>
15. Click Start to verify that the SharePoint list structure is all set up correctly and that it works up to this point.
16. In the Solution Explorer, right-click the project node, and select Add ⇒ New item. In the Add New Item dialog, select Workflow, name it AppListWorkflow, and click Add.
17. In the Specify the workflow name for debugging dialog, click Next.
18. In the “Select the lists you will use when debugging” make the following selections as indicated:
  • The library or list to associate your workflow with: ListToHostWorkflow
  • The history and task lists: <Create New>
Click Next.
19. In the Specify the conditions for how your workflow is started, select “A user manually starts the workflow” and “The workflow starts automatically when an item is created.” Click Finish.
Figure 11 provides the high-level structure for this mock expense approval workflow. It shows in an app for SharePoint the pattern for how to get oriented to the context of the current list and item, retrieve data from the current item, and then use this data to bootstrap a lookup into an external system to retrieve additional data for use in the workflow process. The workflow you build here executes end to end, but the location where you would configure either a SingleTask or ComplexTask activity is stubbed in for reference; you will not configure one of these in this exercise.

FIGURE 11

image
20. In the Workflow Designer, click the title bar for the initial sequence and for its DisplayName type Expense Approval.
21. Click the Expense Approval sequence to select it. Click the Variables tab at the bottom of the designer and create the following variables (the scope for all will be Expense Approval):
  • Name: currentItemGuid Type: System.Guid
  • Name: currentListId Type: System.Guid
  • Name: EmployeeId Type: Int32
  • Name: ManagerName Type: String
  • Name: JsonResponse Type: DynamicValue
  • Name: ReportsToWF Type: Int32
  • Name: ExpenseAmt Type: Double
22. From the Toolbox, drag a Control Flow, Sequence into the Expense Approval sequence, click its name and type, Get current list ID and item.
23. From the Toolbox, drag an SP - Current Context, GetCurrentItemGuid into the Get current list ID and item sequence, and for the Result property type currentItemGuid.
24. From the Toolbox, drag an SP - Current Context, GetCurrentListId into the Get current list ID and item sequence and place it under GetCurrentItemGuid; and in the Result property type: currentListId.
25. From the Toolbox, drag an SP - List Item, LookupSPListItemProperty into the Get current list ID and item sequence and place it under GetCurrentListId; complete the fields for the following properties:
  • ItemGuid: currentItemGuid
  • ListId: ListToHostWorkflow
  • PropertyName: Emp Num
  • PropertyType: Int32
  • Result: EmployeeId
  • DisplayName: LookupSP Emp Num
26. From the Toolbox, drag an SP - List Item, LookupSPListItemProperty into the Get current list ID and item sequence and place it under LookupSP Emp Num, and complete the fields for the following properties:
  • ItemGuid: currentItemGuid
  • ListId: ListToHostWorkflow
  • PropertyName: Expense Amount
  • PropertyType: Double
  • Result: ExpenseAmt
  • DisplayName: LookupSP Expense Amt
Your Get current list ID and item sequence should look like Figure 12 when completed.

FIGURE 12

image

27. From the Toolbox, drag a Control Flow, Sequence into the Expense Approval sequence, below the Get current list ID and item sequence, click its name and type, Retrieve Employee Info.
28. From the Toolbox, drag a Messaging, HttpSend into the Retrieve Employee Info, and complete the fields for the following properties:
  • Method: GET
  • URI (include quotes): "http://services.odata.org/Northwind/Northwind.svc/Employees(" + EmployeeId + ")?$select=EmployeeID,LastName,FirstName,HomePhone,ReportsTo&$format=json"
  • ResponseContent: JsonResponse
  • DisplayName: HttpSend for Emp Info
29. From the Toolbox, drag a DynamicValue, GetDynamicValueProperty<T> into the Retrieve Employee Info, and enter in the fields the following properties (when prompted, select String):
  • PropertyName (include quotes): "d/LastName"
  • Result: EmployeeName
  • Source: JsonResponse
  • DisplayName: Get Emp LastName <String>
30. From the Toolbox, drag a DynamicValue, GetDynamicValueProperty<T> into the Retrieve Employee Info, and enter in the fields for the following properties (when prompted, select Int32):
  • PropertyName (include quotes): "d/ReportsTo"
  • Result: ReportsToWF
  • Source: JsonResponse
  • DisplayName: Get Emp ReportsTo <Int32>
Your Retrieve Employee Info sequence should look like Figure 13 when completed.

FIGURE 13

image

31. From the Toolbox, drag a Control Flow, If into the Expense Approval sequence, below the Retrieve Employee Info sequence, click its name, and type, If block to determine if approval is needed. For the Condition property type: ExpenseAmt > 50.
32. Configure the THEN block; from the Toolbox, drag a Control Flow, Sequence, click the name and type, Manager Approval Required.
33. From the Toolbox, drag a Control Flow, Sequence into the Manager Approval Required sequence, click its name and type, Retrieve Manager Info.
34. From the Toolbox, drag a Messaging, HttpSend into the Retrieve Manager Info, and complete the fields with the following properties:
  • Method: GET
  • URI (include quotes): "http://services.odata.org/Northwind/Northwind.svc/Employees(" + ReportsToWF + ")?$select=EmployeeID,LastName,FirstName,HomePhone,ReportsTo&$format=json"
  • ResponseContent: JsonResponse
  • DisplayName: HttpSend for Manager Info
35. From the Toolbox, drag a DynamicValue, GetDynamicValueProperty<T> into the Retrieve Manager Info, and enter in the fields the following properties (when prompted, select String):
  • PropertyName (include quotes): "d/LastName"
  • Result: ManagerName
  • Source: JsonResponse
  • DisplayName: Get Manager LastName <String>
36. From the Toolbox, drag a Control Flow, If, into the Manager Approval Required sequence, below the Retrieve Manager Info sequence, click its name, and type Do Full Approval Task Here. This is just a stub sequence for where you could implement a CompositeTask, SingleTask; simply send an e-mail; or call out to another service. Implementing the logic to meet the needs of your App for SharePoint is up to you.
37. From the Toolbox, drag a Control Flow, If, into the Manager Approval Required sequence, below the Do Full Approval Task Here sequence, click its name and type, Update List Fields.
38. From the Toolbox, drag an SP - Current Context, SetField, into the Update List Fields sequence, and complete the fields with the following properties:
  • FieldName: Manager
  • FieldValue: ManagerName
  • DisplayName: Set Manager Name
39. From the Toolbox, drag an SP - Current Context, SetField, into the Update List Fields sequence, place it under the Update List Fields, and complete the fields with the following properties:
  • FieldName: Disposition
  • FieldValue, type (include quotes): "Manager Approved"
  • DisplayName, type: Set Manager Approved for Sample
When completed, your THEN block containing the Manager Approval Required sequence should look like Figure 14.

FIGURE 14

image

40. Configure the ELSE block; from the Toolbox, drag a Control Flow, Sequence, click its name and type, Automated Approval Process.
41. From the Toolbox, drag a Control Flow, Sequence, into the Automated Approval Process sequence, click its name and type, Possibly call a Web Service. The point is that some expenses might be able to be automatically approved by an external business process. This is a stub for where that action could take place. External systems could be notified at this point to send notifications, transactions logged to meet audit and compliance policy, and so on.
42. From the Toolbox, drag an SP - Current Context, SetField, into the Automated Approval Process sequence, and complete the fields for the following properties:
  • FieldName: Disposition
  • FieldValue (include quotes): "Auto Approved"
  • DisplayName: Set Auto Approved
When completed, your ELSE block containing the Automated Approval Process sequence should look like Figure 15.

FIGURE 15

image

43. If you have any other icon showing in your workflow other than the yellow icon with the exclamation point, right-click the project and select Rebuild. If this doesn’t clean them all up, then double-click each one in the Error List pane to troubleshoot.
44. Right-click the project and select Deploy. If you are using Office 365 to develop this solution, then the workflow debugger cannot run against a remote server. If you press F5, you will be prompted to turn off the debugger for this solution, which is your choice. In either case, navigate to the site you developed against, click Site Contents, and click the tile for C15WFAppForSP.
45. Your app for SharePoint opens on the Default.aspx page with the link to your workflow list. Follow the link.
46. On the ListToHostWorkflow page, click New item and enter the following properties into the fields:
  • Expense Description: Purchased some office supplies
  • Emp Num (must be a valid Northwind EmployeeID) : 1
  • Expense Amount: 10
Click Save. Keep refreshing the browser until the workflow completes.
47. Click to add another new item and enter the following properties into the fields:
  • Expense Description: Purchased some software
  • Emp Num (must be a valid Northwind EmployeeID): 3
  • Expense Amount: 250
Click Save. Keep refreshing the browser until the workflow completes. Your result should look similar to Figure 16.

FIGURE 16

image

How It Works

This Try It Out showed you how to build in a workflow as an integral component in your App for SharePoint solution. You learned how to get the context of the current list and item being processed from within the Visual Studio design-time environment. This is one of the foundational principles that you will continue to use as your expertise broadens. After you have a context, you can look up any of the properties on the item. You also experienced how to set property values. In building out this workflow, you’ll have noticed that in the Visual Studio environment you work at a lower level when building the workflow than you did in SPD. That’s because the activities in the Visual Studio toolbox are used to compose the actions exposed in SPD. In Visual Studio you work with the base activities themselves. However, this is the only way to include a workflow in an app for SharePoint. App-level workflows must be built with Visual Studio; SPD cannot build workflows against an AppWeb, only a host Web.

Apps for SharePoint developers have the robust capabilities of the Visual Studio Workflow Designer in their toolkit for building business processes, of almost any scope, into their solutions. Developers can also have confidence that whatever they develop, their workflows can run at scale via the Workflow Manager Service online or the Workflow Manager Server on-premises.

 
Others
 
- Developing Workflow Applications for Sharepoint 2013 (part 3) - Workflow and Visual Studio
- Developing Workflow Applications for Sharepoint 2013 (part 2) - Visio Professional, SharePoint Designer, and Workflow
- Developing Workflow Applications for Sharepoint 2013 (part 1) - The Big New Features for SharePoint Designer
- Windows Small Business Server 2011 : Using the Native Consoles (part 2) - Using Server Manager, Directly Opening Native Consoles
- Windows Small Business Server 2011 : Using the Native Consoles (part 1) - Using the Advanced Mode of the Windows SBS Console
- Windows Small Business Server 2011 : Adding and Removing Roles and Features (part 4) - Adding Features
- Windows Small Business Server 2011 : Adding and Removing Roles and Features (part 3) - Adding and Removing Role Services
- Windows Small Business Server 2011 : Adding and Removing Roles and Features (part 2) - Removing a Role
- Windows Small Business Server 2011 : Adding and Removing Roles and Features (part 1) - Add a Role
- SQL Server 2012 : Data-Tier Applications (part 2) - Deploying a Data-Tier Application
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us