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.
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.
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.
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.
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.
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.