Tuesday, March 21, 2017

Implement custom approval logic in a SharePoint 2013 style workflow

Implement custom approval logic in a SharePoint 2013 style workflow

Objective

After completing this lab, you will be able to:
  • Design a simple Approval Workflow logic in Visio 2016.
  • Import the Workflow to SharePoint Designer 2013.
  • Publish the Workflow to your SharePoint Site.

Scenario

In this lab we will simulate a simple laptop request approval workflow. In this scenario you will be acting as Aaron Con, a SharePoint super user who has been given the task to develop a workflow for the organization for approving / rejecting laptop requests from the users. Each user has to submit their own request, no requirement to enable submitting requests on behalf of others. The process has to be simple, but has to prevent people approving their own requests, as well as making modifications to the request after it has been submitted. (In case someone does this, the process should send an email stating this is not permitted and they have to cancel the original request and submit a new one if they want to change.)
The high level design of the Workflow has been created by Emma Lowton, HR Manager in Visio and given to Aaron Con for implementation. Emma Lowton and Aaron Con has already discussed the prerequisites for the process. They agreed that the following Lists and Site Columns will be used to support the Workflow.

Virtual Machines

  1. TR23-CPHOL100
  2. TR23CPHOL100-EX
  3. TR23CPHOL100-CLI

Exercise 1 : Inspect Visio Workflow

The idea of this exercise is to understand the process we are implementing in the workflow. This is an optional task, and you do not have to spend too much time with it. Even skipping this will have no effect on the later exercises.
  1. Open the Workflow created by Emma Lowton
    Log on to the TR23CPHOL100-CLI machine with Aaron Con.
    Note:

    Username: TR23CPHOL100-CLI\aaron.con
    Password: Pa55word
  2. Double-click on Laptop_Approval_WF
    Double-click on Laptop_Approval_WF on the Desktop. This will open Visio and load the file.

    NOTE: At this point, should you receive a warning to activate Visio or activate Office, just close the window
  3. Try to understand the Workflow
    Try to understand the Workflow.

    NOTE: The Workflow has six stages.
  4. Examine each stage
    Examine each stage and try to understand what they do and how they connect to each other.
  5. When you are done with understanding Workflow
    When you are done with understanding the Workflow logic, close Visio.
    IMPORTANT: Please do not save any changes you might have made to the file as that could have an effect on the steps below.
Click Continue to advance to the next exercise.

Exercise 2 : Import Visio Workflow into SharePoint Designer

In this exercise we will simulate a scenario when a business champ creates a Workflow in Visio and gives it to the SharePoint site administrator or super user to deploy it to a SharePoint Site.
  1. Import Visio Workflow into SharePoint Designer
    Open SharePoint Designer by clicking on the  icon in the Taskbar.
  2. Click on the Intranet Home site
    Click on the Intranet Home site in the Recent Sites list:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  3. In the Navigation pane click Workflows
    In the Navigation pane click Workflows.
  4. In the Ribbon
    In the Ribbon, under the Manage section, click Import from Visio.
  5. Choose Import Visio Diagram 2013
    Choose Import Visio Diagram 2013.
  6. Browse to Desktop
    Browse to Desktop and open the Laptop_Approval_WF file.
  7. Give it the name Laptop Approval WF
    Give it the name Laptop Approval WF.
  8. Configure other options for the workflow
    Select  List Workflow from the Workflow Type drop down box.
    Select Laptop Request from the SharePoint List drop down box.
    Click OK.
  9. In the Ribbon under the Manage section
    In the Ribbon under the Manage section, click Views.  Then select Text-Based Designer.

    NOTE: The stages that you have seen in the Visio and the actions are taken over. Spend a minute to understand the structure.

    NOTE: The comments you’ve made in Visio are not visible in this View. To mitigate this issue, you can open the original diagram in Visio in parallel. This way you can easily switch between applications and follow the instructions. It is easier than changing views within SharePoint Designer.
  10. As you can see
    As you can see, the original creator of the diagram did not pay too much attention to the logging. It is not a requirement from the Workflow functionality perspective, however, it is always good to know what is happening. Thus we will add an extra step ourselves just to make sure we can follow the major steps.
Click Continue to advance to the next exercise.

Exercise 3 : Implement the Initializing stage.

In this exercise we will start the actual implementation of the Workflow. As you’ve seen the Workflow in Visio is not bound to any SharePoint site or list. Here we are going to map the actions to fields and variables as well as do any additional actions that might need to be taken.
  1. Edit the actions in the Initializing Stage
    Click right below the header of the Initializing stage, above the Set field to value action.  The orange cursor will appear.
  2. Type log and press Enter
    Type log and press Enter.

    NOTE: As you type in the actions, the IntelliSense will offer you the commands available for that search term. This makes Workflow building much quicker as you gain experience.
  3. Click message and type in “The workflow started.”
    Click message and type in “The workflow started.”, then press Enter.
  4. Take the first Set Field to Value action
    Take the first  Set Field to Value action and click field.
  5. Choose Requestor
    Choose Requestor.

    NOTE: There is no Title field in the list, because we have renamed it to Requestor. The change appears in SharePoint Designer as well.
  6. Click value
    Click value.
  7. Click the function icon
    Click the function icon.
  8. Set up the fields as follows:
    Set up the fields as per the screenshot and click OK.

    Please click on the camera icon on the lower left hand side to view the screenshot.

    NOTE: This is the direct way how you can set the value of the field or Workflow variable. The Data Source gives immediate access to all lists on the same site, other user-defined Workflow variables and the variables available in the Workflow’s context.


    NOTE: The Return field as drop-down might not be available every time. Only if the field has multiple ways values (ex.: People object has Display Name, email, login name, etc.), or if minimal conversion can be performed (ex.: convert a number to a string).
  9. Set up the next Set Field to value action
    Set up the next Set Field to value action by setting Request Cancelled to No.

    According to the Visio diagram, the next step would be to add the manager of the requestor to the Approver field. Unfortunately – unlikely in SP2010 style workflows – there is not a single-action to achieve this goal. We will need to use a web service call.
    IMPORTANT: This is going to be a complex set of actions, please follow the be instructions carefully.
  10. Click right after the row you just modified
    Click right after the row you just modified in the previous step to bring up the cursor. 
  11. Type variable and press Enter
    Type variable and press Enter.
  12. Click workflow variable
    Click workflow variable.
  13. Choose Create a new variable
    Choose Create a new variable.
  14. Add a new variable
    Add a new variable with the information in the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  15. Click OK.
    Click OK.
  16. Click value.
    Click value.
  17. Click the function icon
    Click the function icon and set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  18. Type replace and press Enter
    Right after the new variable you just created, type replace and press Enter.
  19. Click the first string and type in #
    Click the first string and type in #.
  20. Click the second string and type in %23
    Click the second string and type in %23.
  21. Click the third string then the function icon
    Click the third string then the function icon, then set up the fields as per the screenshot, then click OK:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  22. Click Variable: output
    Click Variable: output and change to Variable: ParsedUserName.
  23. Click right after the row you just modified
    Click right after the row you just modified, then type build and press Enter.
  24. Click this.
    Click this.
  25. Click Add to add a Dictionary Item
    Click Add to add a Dictionary Item with the information in the screenshot and click OK:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  26. Click Add to add a Dictionary Item
    Click Add to add a Dictionary Item with the information in the screenshot and click OK.  Then click OK again:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  27. Click Variable: dictionary
    Click Variable: dictionary and create a new variable with some more talkative name: ReqHeader.

    Please click on the camera icon on the lower left hand side to view the screenshot.
  28. In the Ribbon click App Step
    In the Ribbon click App Step to add a special step that is not using the user’s credentials, but a special one for the Workflow App itself.
  29. Add a new action within the app step
    Add a new action within the app step by typing Call and pressing Enter.
  30. Click This
    Click this. The Call HTTP Web Service window will open.
  31. Click on the ellipsis
    Click on the ellipsis (...).

    NOTE: The String Builder window allows you to create texts including multiple lookups from variables as well.
  32. Click Add or Change Lookup and add a lookup:
    Click Add or Change Lookup and add a lookup:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  33. Type in
    Type in
    _api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='Manager')?@v='
    IMPORTANT: You can copy-paste the above text. Please make sure you use the correct single-quote characters.
  34. Click Add or Change Lookup and add a lookup:
    Click Add or Change Lookup and add a lookup:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  35. Type in:
    Type in:
    '
    NOTE: At this point your String Builder window should look like this:

    Please click on the camera icon on the lower left hand side to view the screenshot.

    IMPORTANT: This is a single-quote character you need to use to close the character string with.
  36. Click OK
    Click OK.
  37. Click OK
    Click OK.
  38. Click response and create a new variable:
    Click response and create a new variable:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  39. Drop down the context menu
    Drop down the context menu for the Call HTTP Web Service by right clicking on the action and choosing Properties.
  40. In the RequestHeaders column
    In the RequestHeaders column set Variable: ReqHeader.
  41. Click OK.
    Click OK.

    Once again this would be a good time to log something. For example, the result of the HTTP Web Request. This will help with the troubleshooting. Also you might wish to log the URL used for the web service call. In case the response code is not 200 OK, you could simply paste it into a browser and see what you get back. (This step is not covered in this lab, but optionally you can create that by following the previous steps regarding building the string for the Web Service call above.)
  42. Click right below the App Step
    Click right below the App Step to bring the cursor there:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  43. Type log and press Enter.
    Type log and press Enter.
  44. Click message then the ellipsis (…) and type in:
    Click message then the ellipsis (…) and type in:

    The response code was:
  45. Click Add or Change Lookup and add a lookup:
    Click Add or Change Lookup and add a lookup as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  46. Click OK
    Click OK.
  47. Click OK
    Click OK.

    We get the information from the web service calls into a dictionary type of variable as you’ve seen earlier. This is not directly useable, you need to get the data out of the dictionary into a simple variable type.
  48. Type get below the previous step
    Type get below the previous step and press Enter to add a Get an Item from a Dictionary action.
  49. Click item by name or path
    Click item by name or path and type in d/GetUserProfilePropertyFor.
  50. Click dictionary
    Click dictionary.
  51. Choose Variable: ResponseContent.
    Choose Variable: ResponseContent.
  52. Click item and create a new variable
    Click item and create a new variable as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  53. Take the next Set field to value action
    Take the next Set field to value action.
  54. Click field and choose Approver
    Click field and choose Approver.
  55. Click value
    Click value.

    NOTE: You get a different (new) control here, because the Approver field is of People/Group type. Either you can select the user directly, or you can use one of the lookup options. The latter is what we are going to do.
  56. Choose Workflow Lookup for a User
    Choose Workflow Lookup for a User.
  57. Click Add then set up the fields
    Click Add then set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  58. Click OK
    Click OK.
  59. Click OK
    Click OK.

    Now that we finished with fetching the manager for a user and copying this information into the appropriate field, we can continue with the original Workflow description.
  60. Take the next Set field to value action
    Take the next Set field to value action.
  61. Click field and choose WF Outcome.
    Click field and choose WF Outcome.
  62. Click value
    Click value.
  63. Type Pending
    Type Pending.
  64. Take the Set workflow variable to value action
    Take the Set workflow variable to value action.
  65. Click workflow variable
    Click workflow variable and create a new variable with the information in the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  66. Click value then the function icon
    Click value then the function icon, then set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  67. Click OK
    Click OK.
  68. Save the current state of the Workflow
    Save the current state of the Workflow by pressing CTRL+S on the keyboard, or by clicking on the save button in the Ribbon.
Click Continue to advance to the next exercise.

Exercise 4 : Implement the Creating Approval Task stage

In this exercise we will create the task for the manager, and send an email to the requestor that the request has been created. All tasks in this exercise will be performed within the boundaries of the Creating Approval Task stage.
  1. Edit the actions in Creating Approval Task Stage
    In the Creating Approval Task, click this user to open the Assign a Task window.
  2. Click the ellipsis (...)
    Click the ellipsis (...) next to the Participant field.
  3. Choose Workflow Lookup for a User.
    Choose Workflow Lookup for a User.
  4. Click Add then set up the fields
    Click Add then set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  5. Click OK.
    Click OK.
  6. Click OK.
    Click OK.
  7. Click the ellipsis (...)
    Click the ellipsis (...) next to the Task Title field and type in:

    Laptop request for:
  8. Click Add or Change Lookup and add a lookup:
    Click Add or Change Lookup and add a lookup:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  9. Click OK.
    Click OK.
  10. Click OK.
    Click OK.
  11. Click Open editor for body and construct a message
    Click Open editor for body and construct a message. Something like in the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
    Please use the techniques learned earlier to add the variables to the body of the email.

    NOTE: For the placeholders (like [%Current Item:Approver%]) you have to use the Add or Change Lookup button.
  12. Click OK.
    Click OK.
  13. Expand the Task Options section.
    Expand the Task Options section.
  14. Uncheck the Wait for task completion box.
    Uncheck the Wait for task completion box.
  15. Expand the Email Options section.
    Expand the Email Options section.
  16. Click Open Email Editor
    Click Open Email Editor.

    NOTE: Here you have a pre-defined email editor control. As you can see, this is a rich text control field where you can create visually attractive emails.

    NOTE: It is not possible to insert pictures or file attachments here.
  17. Click on the big [%Task: Title%] text:
    Click on the big [%Task: Title%] text:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  18. Click the Hyperlink icon
    Click the Hyperlink icon in the Controls pane in the upper-right part of the window.

    NOTE: The Text to display and Address fields are both using variables that you could use in your own email style as well.
  19. Click Cancel.
    Click Cancel.
  20. If you want, you can make modifications
    If you want, you can make modifications on this part here. We are not going to do that due to the lack of time in this lab, so please click Cancel.
  21. Expand the Outcome Options section.
    Expand the Outcome Options section.
  22. Drop down the Task content type menu
    Drop down the Task content type menu.

    NOTE: There is no option to select the custom Content Type that Aaron Con created as a prerequisite for this task. (See the Scenario section of this lab for further information.) It is because the Workflow Task list does not have this Content Type associated.
    LaptopApprovalCT does appear in the drop down list for the Task content type menu.  For now, don't select it and move onto the next step.
  23. Click OK.
    Click OK.
  24. Save the Workflow
    Save the Workflow.
  25. Open Internet Explorer
    Open Internet Explorer.

    NOTE: You should be taken to the http://intranet.tr23cphol202.com/ site automatically. Should the page not open by default, please open it manually.
  26. Click Workflow Tasks in the Navigation Pane
    Click Workflow Tasks in the Navigation Pane.
  27. In the Ribbon click List, then List Settings.
    In the Ribbon click List, then List Settings.
  28. In the Content Types section
    In the Content Types section click Add from existing content types.
    If you already see the following listed under Content Type:
    LaptopApprovalCT
    Then skip this step and move on to step 32.
  29. In the Available Site Content Types list
    In the Available Site Content Types list find LaptopApprovalCT and click it.
  30. Click Add
    Click Add.
  31. Click OK.
    Click OK.
  32. In the Content Types section
    In the Content Types section click the Workflow Task content type.
  33. Delete this content type
    Click Delete this content type and confirm by clicking on OK.
  34. Delete the below columns
    Delete the below columns by clicking on their name, then on the Delete button on the next page and confirming your deletion with the OK button:

    % Complete

    Predecessors

    Priority
  35. Go back to SharePoint Designer
    Go back to SharePoint Designer.
  36. In the Quick Access Toolbar click Refresh
    In the Quick Access Toolbar click Refresh.

    Please click on the camera icon on the lower left hand side to view the screenshot.
  37. In the Assign a Task action
    In the Assign a Task to action, click Variable: Manager.
  38. Expand the Outcome Options
    Expand the Outcome Options, then drop down the Task content type menu and set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  39. Click OK.
    Click OK.
  40. In the next Email action, click these users
    In the next Email action, click these users.
  41. Set up the fields as follows
    Set up the fields as follows as you have seen in the previous steps:

    NOTE: Please copy-paste the corpus from below to not waste time with typing.

    Hello ,

    A new task has been created and assigned to  regarding the new laptop request you have submitted. The ID of the task is: .

    This is an FYI email, no action is required. Please wait for  to finish the task.

    Many thanks.

    IMPORTANT: You have to add the variables manually to match the screenshot.

    IMPORTANT: When you use the email field, you have to select Email Address in the Return field as drop-down menu.
  42. Click OK.
    Click OK.

    Also, it is advised here to add a log entry so that later you could follow what is happening with the Workflow Instance.
  43. Type log under the previous action
    Type log under the previous action and press Enter.
  44. Click message and type in:
    Click message and type in:

    The task has been created for the approver.
Click Continue to advance to the next exercise.

Exercise 5 : Implement the Waiting for Actions stage.

In this exercise we will configure the Workflow to wait until either the Task is finished, or the original request is changed. The evaluation of the actions will happen in a later stage.
  1. Edit the actions in the Waiting for Actions Stage
    Take a look on the related section in the Visio diagram:

    Please click on the camera icon on the lower left hand side to view the screenshot.

    NOTE: You can always refer to the original Workflow created in Visio for guideline on what needs to be done.

    As you can see, the originator of the Workflow expects us to create a single action that detects if the related Task has changed. Unfortunately – just as with the manager lookup – this is not possible with a single action, thus we will have to change this Stage a little bit as well.
  2. Add a Set workflow variable
    Add a Set workflow variable to value action to the beginning of the Waiting for Actions Stage.
  3. Click workflow variable
    Click workflow variable and create a new one as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  4. Click value and set it to NoChange
    Click value and set it to NoChange.
    IMPORTANT: The default behavior of the Parallel block is to execute all parallel actions and proceed only after all of them have been executed. To change this behavior, we need to set a Boolean value to True and feed it as the CompletionCondition parameter of the Parallel block. Thus, we will need to create a new variable.
  5. Right-click on the header of the parallel section:
    Right-click on the header of the parallel section:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  6. Choose Advanced Properties
    Choose Advanced Properties.
  7. Drop down the menu
    Drop down the menu and choose Create a new variable as per the screenshot.

    Please click on the camera icon on the lower left hand side to view the screenshot.
  8. Click OK.
    Click OK.
  9. Click OK.
    Click OK.
  10. Click right at the beginning of
    Click right at the beginning of the parallel action to add the cursor there:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  11. Type loop and hit Enter
    Type loop and hit Enter.
  12. Choose Loop with Condition
    Choose Loop with Condition.

    NOTE: At this point this section of the Workflow should look like this:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  13. Click any of the value equals value text
    Click any of the value equals value text.
  14. Set up the fields
    Set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  15. Click OK.
    Click OK.
  16. From the Ribbon add an If any value equals value
    From the Ribbon click Condition and add an If any value equals value condition:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  17. Click the first value then the function icon
    Click the first value then the function icon.
  18. Set up the fields
    Set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  19. Click OK.
    Click OK.
  20. Click equals and change it to not equals.
    Click equals and change it to not equals.
  21. Click the second value then the function icon.
    Click the second value then the function icon.
  22. Set up the fields
    Set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  23. Move the cursor under the
    Move the cursor under the (Start typing or use Insert group on the Ribbon.)
  24. Type variable and press Enter
    Type variable and press Enter.
  25. Click workflow variable
    Click workflow variable and choose Variable: ChangeAction.
  26. Click value then type TaskChange
    Click value then type TaskChange.
  27. Move the cursor under the previous action
    Move the cursor under the previous action and type variable and press Enter.
  28. Click workflow variable
    Click workflow variable and create a new variable as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  29. Click value then the function icon.
    Click value then the function icon.
  30. Set up the fields
    Set up the fields as per the screenshot, then close the windows by clicking on OK:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  31. Move the cursor under the previous action
    Move the cursor under the previous action and type variable and press Enter.
  32. Click workflow variable
    Click workflow variable and choose Variable: ExitParallelBlock.
  33. Click value and choose Yes
    Click value and choose Yes.
  34. Add an Else Branch
    Add an Else Branch by clicking on the relevant option in the Ribbon.
  35. Type pause and press Enter
    Type pause and press Enter.
  36. Choose Pause for Duration
    Choose Pause for Duration.
  37. Click 5 and change it to 1
    Click 5 and change it to 1.

    NOTE: There are many ways to achieve this goal. We could be checking every change in the Workflow Task list, then check if the changed item is the one bound to this Workflow instance, or – as we’ve chosen now – periodically check if the item has been changed.
    There is no “good” or “best” solution. You need to decide which is more likely to happen. If there are a lot of tasks in the Workflow Task list and they are changing frequently, plus there are a lot of Workflow instances running at the same time, you are better with periodically checking if the Task bound to the given Instance has been changed, as this process will have a smaller footprint on your environment, but of course, your Workflow will have some unnecessary waiting in there
    Of course if the number of running instances is not that high you should be using the approach where each item’s change in the Workflow Task list will trigger the action in the Workflow. In this case the Workflow logic would look like this. (We are not going to implement this in this lab.)

    Please click on the camera icon on the lower left hand side to view the screenshot.

    IMPORTANT: In a production environment never change this value to lower than 5 minutes.
  38. Select each of the actions
    Select each of the actions in the Step: Sequence and Delete them.
  39. Right-click on the next action
    Right-click on the next action after the Sequence and choose Move Action Up.

    Please click on the camera icon on the lower left hand side to view the screenshot.
  40. Click field and choose Request Cancelled
    Click field and choose Request Cancelled.
  41. Click value and choose Yes
    Click value and choose Yes.

    NOTE: At this point the main part of the Stage should look like this:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  42. Type variable and press Enter
    If you have not already done so, Type variable and press Enter underneath "The Following actions will run in Sequence" in Step: Sequence.
  43. Click workflow variable
    Click workflow variable and choose Variable: ExitParallelBlock.
  44. Click value and choose Yes.
    Click value and choose Yes.

    NOTE: Take a moment to understand what the “Wait for Request Cancelled to equal Yes” action really does. It triggers only when the original item modification is in the change of the value of the “Request Cancelled” column. It won’t trigger when any other parameter of the item is changed.
    Practically this means two things for us:

    1. The Workflow will only proceed if either the associated task is changed, or the request is cancelled.
    2. The approver – when approving or rejecting the request won’t know if the item was changed with other parameters (ex.: laptop brand change).
    IMPORTANT: Due to the limited time available for this lab, we are going to handle the item change modification in a limited manner. More sophisticated logic can be built in a real-life scenario.
  45. In the Transition to stage section
    In the Transition to stage section click the first value of the condition, then the function icon.
  46. Set up the fields as per the screenshot:
    Set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  47. Click OK.
    Click OK.
  48. Click the second value and type in TaskChange
    Click the second value and type in TaskChange.

    This concludes the implementation of the Waiting for Actions stage.
Click Continue to advance to the next exercise.

Exercise 6 : Implement the Task Modified stage.

In this exercise we will handle the change that happened to the Task associated with the Workflow instance.

NOTE: Just as earlier, the Workflow is not bulletproof. If the change in the associated Task is not in the Outcome field, we will have to handle that separately. As we do not have enough time in this lab, we are not going to implement that, but probably by now you know already what actions should be taken.
  1. Edit the actions in the Task Modified Stage
    In Task Modified Stage Click field and choose WF Outcome.
  2. Click value then the function icon
    Click value then the function icon.
  3. Set up the fields as per the screenshot:
    Set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.

    The next Stage in the Text-Based Designer is the Finished Stage. For brevity we are going to move that to the end of the Workflow.
  4. Right-click on the header of the Finished Stage
    Right-click on the header of the Finished Stage.
  5. Choose Move Down.
    Choose Move Down.
Click Continue to advance to the next exercise.

Exercise 7 : Implement the Item Modified stage

In this exercise we will handle the situation when the request is cancelled.

NOTE: Because the way we implemented the Waiting for Actions Stage, this Stage can be simplified. As explained earlier, originally we were to handle if the change in the original item is not on the Request Cancelled field. Since it is not detected due to the earlier change we have made, we can leave this out.  Certainly if this is important, you will have to implement the necessary logic into your Workflow.
  1. Edit the actions in the Task Modified Stage
    In the Item Modified Stage highlight the whole condition by clicking on the left edge of it:

    Please click on the camera icon on the lower left hand side to view the screenshot.

    NOTE: If you’ve done everything correctly, the whole section will get a light-blue background.
  2. Press Delete.
    Press Delete.
  3. Confirm the action by clicking on OK
    Confirm the action by clicking on OK.
  4. Type in update and press Enter
    Type in update and press Enter.
  5. Click this list.
    Click this list.
  6. Set up the fields as per the screenshot:
    Set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  7. Click Add and set up the fields
    Click Add and set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  8. Click Add and set up the fields
    Click Add and set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  9. Click OK.
    Click OK.
  10. Click below the Update item action.
    Click below the Update item action.
  11. Type field and press Enter
    Type field and press Enter, then choose Set Field in Current Item.
  12. Click field and choose WF Outcome.
    Click field and choose WF Outcome.
  13. Click value and type Cancelled.
    Click value and type Cancelled.
  14. Click below the Set field action.
    Click below the Set field action.
  15. Type variable and press Enter.
    Type variable and press Enter.
  16. Click workflow variable
    Click workflow variable and choose LaptopApprovalOutcome.
  17. Click value and type Cancelled.
    Click value and type Cancelled.
  18. In the Transition to Stage section
    In the Transition to Stage section highlight the whole condition by clicking on the left edge of it.
  19. Press Delete.
    Press Delete.
  20. Confirm the action by clicking on OK.
    Confirm the action by clicking on OK.
  21. Type go and press Enter.
    Type go and press Enter.
  22. Click a stage and choose Finished.
    Click a stage and choose Finished.
Click Continue to advance to the next exercise.

Exercise 8 : Implement the Finished Stage

In this exercise we finally implement the last actions of our Workflow. We really do not have much back, but send out the information email to the requestor about the outcome of the Workflow.
  1. Edit the actions in the Finished Stage
    In the Finished Stage click the first value the function icon
  2. Set up the fields as per the screenshot:
    Set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  3. Click the second value and type Approved
    Click the second value and type Approved.
  4. Click these users
    Click these users in the main branch of the If condition.
  5. Click the address book icon
    Click the address book icon at the end of the To field.
  6. Choose Workflow Lookup for a User
    Choose Workflow Lookup for a User.

    Please click on the camera icon on the lower left hand side to view the screenshot.
  7. Set up the fields as per the screenshot:
    Set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  8. Click OK.
    Click OK.
  9. Click OK.
    Click OK.
  10. Into the Subject field type
    Into the Subject field type in “Your laptop request has been Approved”
  11. Edit the email message with the learned techniques
    Edit the email message with the learned techniques to reflect the screenshot below:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  12. Click OK.
    Click OK.
  13. Click these users
    Click these users in the Else branch of the If condition.
  14. Click the address book icon
    Click the address book icon at the end of the To field.
  15. Choose Workflow Lookup for a User
    Choose Workflow Lookup for a User.

    Please click on the camera icon on the lower left hand side to view the screenshot.
  16. Set up the fields as per the screenshot:
    Set up the fields as per the screenshot:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  17. Click OK.
    Click OK.
  18. Click OK.
    Click OK.
  19. Into the Subject field type
    Into the Subject field type in “Your laptop request has NOT been approved”
  20. Edit the email message
    Edit the email message with the learned techniques to reflect the screenshot below:

    Please click on the camera icon on the lower left hand side to view the screenshot.
    Please use the techniques learned earlier to add the variables to the body of the email.
  21. Click OK.
    Click OK.

    Here you might wish to add another log entry that the workflow finished.
  22. Click above the Transition to Stage section
    Click above the Transition to Stage section.
  23. Type in log and press Enter.
    Type in log and press Enter.
Click Continue to advance to the next exercise.

Exercise 9 : Publish the Workflow and test the functionality

In this exercise we finally publish the workflow and test its functionality with some test users.
  1. Publish the workflow
    In the Ribbon click Check for Errors.
  2. If you did everything correctly
    If you did everything correctly, you should see a confirmation that the workflow contains no errors.
  3. Click OK.
    Click OK.
  4. In the Breadcrumb of the Workflow click
    In the Breadcrumb of the Workflow click Laptop Approval WF to close the Text-Based Designer and go back to the settings of the Workflow.
  5. In the Start Options section set
    In the Start Options section set Start workflow to start automatically when an item is created.
  6. In the Ribbon click Publish
    In the Ribbon click Publish.
  7. Click OK to confirm
    Click OK to confirm that you intend to use App Step in your workflow.
  8. Open Internet Explorer
    Open Internet Explorer.
  9. Click the gear icon
    Click the gear icon in the top-right corner of the window, then choose Site settings:

    Please click on the camera icon on the lower left hand side to view the screenshot.
  10. Under the Site Actions section
    Under the Site Actions section click Manage site features.
  11. Locate the Workflows
    Locate the Workflows can use app permissions feature and activate it.
  12. Go back to Site Settings
    Go back to Site Settings by clicking it in the Breadcrumb menu.
  13. Under the Users and Permissions section
    Under the Users and Permissions section click Site app permissions.
  14. Copy the GUID of the workflow to the clipboard:
    Copy the GUID of the workflow to the clipboard:

    Please click on the camera icon on the lower left hand side to view the screenshot.
    IMPORTANT: The GUID starts after the last pipe ( | ) and ends before the at sign (@).
  15. In the browser’s address bar change the URL
    In the browser’s address bar, change the URL and go to the following web address below:

     http://intranet.tr23cphol202.com/_layouts/15/start.aspx#/_layouts/15/appinv.aspx
    You can copy paste the URL for easier access.
  16. Copy-paste the below code
    Copy-paste the below code into the Permission Request XML box:



     

  • Click Create.
    Click Create.
  • Click Trust It
    Click Trust It.
    IMPORTANT: You have to be Tenant Administrator to be able to perform this action. In this lab this permission is given to Aaron Con. In real life scenario you would need to grant that manually.
  • Click Continue to advance to the next exercise.

    Exercise 10 : Test Workflow functionality 1

    Now that we have the workflow ready, we can go ahead and test the workflow functionality.
    1. Log on to the TR23CPHOL202-CLI machine
      Log on to the TR23CPHOL202-CLI machine with Ellen Adams. (For username and password check the introduction section of the document.)
    2. Open Internet Explorer
      Open Internet Explorer.
    3. In the left Navigation pane click Laptop Request
      In the left Navigation pane click Laptop Request.
    4. Click new item and fill in the fields as follow:
      Click new item and fill in the fields as follows:

      Please click on the camera icon on the lower left hand side to view the screenshot.

      NOTE: This is quite unlikely that someone is filling up the request like this, but we would like to simulate what the workflow does with the request.
    5. Click Save.
      Click Save.
    6. Wait a few seconds and refresh the page (F5)
      Wait a few seconds and refresh the page (F5).
    7. Click on the link in the Laptop Approval WF column
      Click on the link in the Laptop Approval WF column.
    8. At this point you should see this:
      At this point you should see this:

      Please click on the camera icon on the lower left hand side to view the screenshot.
    9. Log on to the TR23CPHOL202-CLI machine
      Log on to the TR23CPHOL202-CLI machine with Emma Lowton. (For username and password check the introduction section of the document.)
    10. Start Outook
      Start Outook.

      NOTE: At this point, should you receive a warning to activate Visio or activate Office, just close the window
    11. In the email click on Laptop request
      In the email click on Laptop request for: Ellen Adams.
    12. In the Ribbon click Edit Item
      In the Ribbon click Edit Item.
    13. Change LaptopApprovalOutcome to Approved
      Change LaptopApprovalOutcome to Approved.
    14. Click Save
      Click Save.
    15. Log back on with Ellen Adams
      Log back on with Ellen Adams.
    16. Open Internet Explorer
      Open Internet Explorer.
    17. Go to the Laptop Requests list
      Go to the Laptop Requests list.
    18. Click on the link in the Laptop Approval WF column
      Click on the link in the Laptop Approval WF column.
    19. See that the status is updated
      See that the status is updated. Even though we do not have much logging, you should see the entries as the Workflow proceeded.
    20. Open Outlook
      Open Outlook.
    21. Confirmation email
      See that Ellen Adams have received the confirmation email.
    Click Continue to advance to the next exercise.

    Exercise 11 : Test Workflow functionality 2

    1. Test Workflow functionality 2
      If you still have time left, test the workflow with another user. For example, with Tiffany Mach, and check if the workflow works fine if you cancel the Request.

      You can also test the Workflow with Aaron Con. What happens when he submits a request?

       
    Congratulations!

    In this lab you’ve seen how a custom approval process can be implemented in SharePoint 2013. Since this is just an example, we did not cover all possible scenarios. Nor we have made any modification on the forms.

    The above process might seem complicated, but as you could see, a complex solution can be done even with the built-in functionality. 3rd party solutions like Nintex, K2 and other competitors can provide you a seemingly simpler user interface, but you have to evaluate if the added value is comparable with the price of these solutions.

    If you liked this workshop and would like to learn more about how to create SharePoint 2013 style Workflows in SharePoint Designer, please get in contact with Zsolt Illes (zsolti@microsoft.com).

    Click Continue to close and finalize this lab.

    No comments: