How To: Add and View Workflow Attachments

This article illustrates one method for adding and viewing attachments to a workflow using a system SmartObject. You can use out-of-the-box system SmartObjects in a workflow which gives you the ability to list all attachments added to the workflow during its lifetime. This is especially useful when you need to gather attachments from more than one person and at different stages of the workflow, but have them in a single place.

To learn about adding and viewing comments using a system SmartObject, see How To: Add and View Workflow Comments.

File attachments from multiple users in a single workflow instance
Get Attachment on Subview

Scenario

You work in Human Resources. You have created an online form for employees to submit leave requests. Your form includes an option to attach supporting documents such as invoices or itineraries. You have a workflow that includes two tasks: one for approving the request and the other for reworking it. Both task forms have a view for attaching files.

For this scenario we use sample users. You can create your own test users to work with. Depending on the type of scenario you build, you may need to configure specific security settings such as Designer authorization for these users. For more information about managing your environment see the Administer section.

Steps

For this scenario, you create a SmartBox SmartObject to store request details, then use a system SmartObject to store attachments. You create views from both SmartObjects, then a form that contains the views. Finally, you create a workflow with a two task steps for approving and reworking the request.

Setup Steps

The following steps set up the scenario from start to finish. If you want to skip the setup steps and view the topic step, go to Create views from the Workflow Attachment system SmartObject.

  1. From K2 Designer, create a SmartBox SmartObject called Leave Requests. Use the table below as a guide for adding properties. (Optional: create categories first to keep your work organized. All Items > How To > Leave Requests)
    PropertyType
    First NameText
    Last NameText
    Leave Start DateDate
    Leave End DateDate
    1. Launch K2 Designer. On the designer landing page, click Browse.
      If you do not know how to access K2 Designer, see Accessing K2 Sites.
    2. Create new categories to keep your work organized. Expand the All Items node. Right-click All Items and select New Category. Name the category
      How To
      then right-click How To and select New Category once again. Name the category
      Leave Requests.
      Categories are folders you create to keep your work organized. If you are working in a shared environment, consider adding your initials or some other unique identifier to separate your work from others.
      Create Categories
    3. Right click the Leave Requests category and select New SmartObject.
    4. Name the SmartObject
      Leave Requests
      then confirm the SmartBox option is active. Click Create.
      Create SmartBox SmartObject
    5. Now you are ready to add properties. Properties are like the columns in a table. You define the property name and data type. Click Add. For the first property, enter
      First Name
      then keep the default type, Text. Click <Add property> to add the next item.
      Add Property
    6. Use the table below as a guide for adding the remaining properties. Click OK to save your work.
      PropertyType
      Last NameText
      Leave Start DateDate
      Leave End DateDate
    7. Your Leave Requests SmartObject should look like the image below. Click Finish (located near the upper right corner of your screen) to save and exit the SmartObject.
      Leave Requests SmartObject
  2. Generate an item view from the Leave Requests SmartObject. Name it Leave Requests Item.

    Next, you generate a view from the SmartObject. Generating a view from a SmartObject binds it to the SmartObject and makes the properties available for use in the view. The properties become the view controls for entering data. Because the controls are bound to the SmartObject, K2 knows to save view content to its corresponding data source property.

    1. Right-click the Leave Requests SmartObject and select Generate Views.
    2. Check the Item box, then name the view
      Leave Requests Item
      and click OK.
      Generate Item View
    3. The view appears in your category. (Your categories may not match the image below if you gave them different names. This demonstration assumes the category names below.)
      Leave Requests Category

Create views from the Workflow Attachment system SmartObject

Using the Workflow Attachment system SmartObject, create an item view for adding attachments, then create a list view for displaying attachments.

  1. Design an item view from the Workflow Attachment system SmartObject. Name the view Attachment Item. Save the view to your Leave Requests category. Format the layout for one column. Create Labels and Controls for the File field (only).
    1. You use the same steps as above to generate views from system SmartObjects. Depending on your environment, you may need to expose system objects first. Review your categories. You should see a category called System. If you do not, click the All link at the bottom of your screen. Check the box to show System Objects.
      Show System Objects
    2. Expand the System category, then expand Workflow > Attachments. You see the Workflow Attachment SmartObject.
      Workflow Attachment SmartObject
    3. Right-click the SmartObject and select Design View.
    4. Name the view
      Attachment Item
      then click the ellipses to change the Category to Leave Requests. You want to save all your work in the same category. Confirm Item View is the View Type. Click Create.
      Generate Item View
    5. Click Create Labels and Controls.
      You have two options for your view layout. K2 can create a layout table and add controls that you specify next, or K2 can create a layout table only, and you add controls yourself. The first option is the quickest, while the second option gives you full control over the layout of your view.
      Create Labels and Controls
    6. On the Create Labels and Controls screen, change the Columns value to
      1.
      For the included Fields, check the File box and click OK. You only need the control for attaching files.
      Change Columns Select File
    7. The view should look like the image below. Click Finish to save and exit. (If your view format and style is different from the image, it's OK to continue. You can change it later.)
      Attachment View
  2. Design a list view from the Workflow Attachment system SmartObject. Name the view Attachment List. Save the view to your Leave Requests category. Uncheck the option to Call this method when the form loads. Create Labels and Controls for ID, File Name, Created By, and Created Date. Enable list editing, but do not select any buttons. Uncheck the Visible option for the ID column to hide it on the live view.

    You have generated the view used to upload new attachments. Next, you generate a list view that displays all the attachments for the workflow.

    1. Right-click the Workflow Attachment SmartObject and select Design View.
    2. Name the view
      Attachment List
      then change the View Type to List. Change the Category to Leave Requests. Uncheck the option to Call this method when the form loads. This option loads all records from the SmartObject when the view launches. Instead, you add a rule action later that populates the list with the current workflow attachments. Click Create.
      Generate List View
    3. Click Create Labels and Controls.
    4. On the Create Labels and Controls screen, include the following fields: ID, File Name, Created By, and Created Date. Check the box to Enable list editing, Edit all rows, but don't add any buttons or enable the new row link. In a later optional step, you call a method to open a subview when you double-click a row in the list. You cannot double-click a row if the list is not editable. Click OK.
      Included Fields
    5. Select the ID column. In the Column pane on the right side of your screen, uncheck the Visible property under the General heading. In a later optional step, you open a subview to display the attachment. The ID property is required to open the file. The ID does not need to be visible.
      Make ID Column Not Visible
    6. Click Finish to save and exit.
    7. You now see the two new views saved to your Leave Requests category.
      Leave Requests Category

  3. From the Leave Requests category, create a new form called Leave Requests Form. Add the three views in this order: Leave Requests Item, Attachment Item, and Attachment List. Add a Parameter called ProcInstID with a number data type. Finish the form.
    1. Right-click the Leave Requests category and select New Form.
      Views are not accessible on their own. You must contain them within a form. Forms are the public facing interface that you open with a browser. You can use a view in more than one form and one form can contain more than one view.
    2. Name the form
      Leave Requests Form
      then click Create.
      Create New Form
    3. Click the Views tab on the left side of your screen. Navigate to the Leave Requests Item view, and drag it onto the design canvas.
      Drag First View onto Canvas
    4. You may see a different format and style on your screen from the images in this article. This difference is most likely due to the theme you are using. To match the images in this article, click the Properties tab, and change the Theme property to Lithium.
      Lithium Theme
    5. Next, add the Attachment Item view to the design canvas. As you drag the view onto the canvas, placeholders appear. Drop the view into the placeholder below the Leave Requests Item view.
      Add Attachment Item View
    6. Add the Attachment List view below the Attachment Item view.
    7. Your three views should look like the image below.
      Three Views

    8. (Optional) Change the view titles so they match the view functions. For the first view, click (Enter View Title) and change it to
      Leave Details
      then press <ENTER> to set the title.
      Change View Title
    9. Change the second view title to
      Attach File
      and the third view title to
      Saved File Attachments.
      New View Titles
    10. Before saving your form, create a parameter that stores the ID of the current workflow instance. The ID is required by the Workflow Attachment SmartObject for saving and loading records. Click the Parameters tab. Click Add Parameter. Name the new parameter
      ProcInstID
      and change the data type to Number. Click Finish to save and exit.
      Add Parameter
  4. Create a workflow from the Leave Requests Form called Leave Requests. Configure the Start step so that the workflow starts when you click the Save button. (You can use the Do it for me! option to set the start rule actions.)

    Next, you create a workflow that contains two task steps. The first task is to approve the request and the second task is to rework it. Of course, in the real world, a workflow for leave requests is more complicated, but the purpose of this demonstration is to show you how attachments added during multiple tasks appear in one list view.

    1. Right-click the Leave Requests Form and select Design Workflow.
    2. The K2 Workflow Designer launches. Name the workflow
      Leave Requests
      then click Create.
      Design Workflow
    3. You see a Welcome screen with an interactive panel. You can click the right and left arrows to learn more about the workflow designer. Click Close to proceed to the design canvas.
      Welcome Screen
      You may see additional interactive pop-ups while using the designer. Click Got It or Close to continue.
      Got It

      Begin by configuring the rule that starts the workflow. In this case, you want the workflow to start when you click the Save button.

    4. Click the Start step to select it. (Selected steps have a blue border.) Expand the Configuration Panel.
      The Configuration Panel allows you to configure and customize the steps you add to your workflow.
      Edit Start Step
    5. Notice the Start Events indicate which form to use, but there is no start rule action. You want to configure the workflow to start when you click the Save button. Click Edit.
      Start Events
    6. The Start Workflow from a Form wizard launches.

    7. On the References screen, notice K2 discovered the Leave Requests SmartObject and the Workflow Attachment SmartObject. (Click the references bar to expand it if necessary.) Both SmartObjects are bound to views in the Leave Requests Form, so K2 creates a reference to them. You can use the references throughout the workflow build. Click Next.
      References Screen
    8. On the Start Rule screen, click Do it for me!. With this option, K2 configures the start rule action for you. You can walk through each setting and make your own configurations by clicking the Help me configure it option. Click Next.
      Help Me Configure It
    9. The summary screen gives an overview of the changes K2 makes to the Leave Requests Form to integrate it with the workflow. Notice that K2 adds a rule action to start the workflow after you click the Save button. You edit this rule action in a later step. Click Save and Finish. When you see the success check, click OK.
      Save and Finish
    10. Back on the Start Events screen in the Configuration Panel, notice the start rule now exists. Collapse the Configuration Panel by clicking the slider.
      Start Rule
  5. Complete the workflow steps using the table below as a guide. Deploy the workflow. Grant Everyone > Start and View rights.
    Step > PropertyValue
    Task 
    InstructionsA leave request requires your approval. Select an action from the drop-down list, and click Submit to send your decision.
    ActionsApproved
    Rejected
    Rework
    FormSmartForm > Leave Requests Form
    The wizard launches. Select Do it for me! to let K2 configure the form settings.
    ParametersMap the Context Browser > Workflow > Workflow > ID to the ProcInstID parameter.
    RecipientsAssign the task to Bob Maggio (or search for and select a different user who can help you test later). You can use Originator Manager if you have access to their email notifications.
    PropertiesManager Approval
    DecisionConnect this step to the Manager Approval step.
    Task 
    InstructionsYour request requires rework.
    ActionsRework Complete
    FormSmartForm > Leave Requests Form
    The wizard launches. Select Do it for me! to let K2 configure the form settings.
    ParametersMap the Context Browser > Workflow > Workflow > ID to the ProcInstID parameter.
    RecipientsOriginator
    PropertiesOriginator Rework
    DecisionConnect this step to the Originator Rework step.
    PlaceholdersAdd three placeholders and connect them to the following outcome lines: Approved, Rejected, Rework Complete.

    You are now ready to add the first task step. This step assigns a task to the request approver, where they can choose to approve, reject, or rework the request. The rework option sends the workflow back to the requester.

    1. From the Toolbox > Basic node, drag a Task step into the empty placeholder below the Start step.
      Add Task Step
    2. Notice the red warning badge on the Task step. This badge indicates there are required settings in the Configuration Panel. When you expand the panel, you see the same badge next to the required settings.
      Required Settings
    3. Click the Task step and expand the Configuration Panel. Click the Task tab to make it active (if it is not already). For the instructions, enter
      A leave request requires your approval. Select an action from the drop-down list, and click Submit to send your decision.
      For the Actions, click the Add(+) icon. Enter
      Approved
      then click the Add(+) icon once again. Enter
      Rejected.
      Add a third action,
      Rework.
      The task recipient chooses one of the actions you specify for their decision on the leave request.
      Configure Task Actions
    4. Click the Form tab. For the Form Type, select SmartForm. For the Form, select Leave Requests Form. (If you do not see the form in the drop-down list, click Browse, then navigate to where you saved the form.)
      Set Form Values
    5. The Open Task on a Form wizard launches.

    6. On the References screen, click Next.
    7. On the Open Task screen, keep the default Do it for me! and click Next.
    8. On the summary screen, review the changes K2 makes to your form. Click Save and Finish. When you see the success check, click OK.
    9. Notice the ProcInstID parameter under the Parameters heading. This is the same variable you added when you created the form. You must map the ID of the current workflow instance to this parameter so you can use it later to load the correct attachments.
      Parameters

    10. Expand the Context Browser.
      The Context Browser contains references, variables, functions, and SmartObject properties. At runtime, K2 replaces references and variables with live data. For example, K2 replaces the ProcInstID parameter with the ID of the current workflow instance.
      Expand Context Browser
    11. Click the Workflow tab. Expand the Workflow node. Drag the ID property into the ProcInstID text box. Collapse the Context Browser by clicking the slider.
      Map ID Parameter
    12. Click the Recipients tab. Click the Originator bar and select Browse. Search for Bob Maggio. Select Bob's name in the results pane, then click OK. (If working in your own environment, search for a user who can help you test later. You can also use Originator Manager if you have access to their email notifications.)
      Set Task Recipient
      Select User
    13. Click the Properties tab. Change the step name to
      Manager Approval.
      Collapse the Configuration Panel.
      Change Step Name
    14. From the Toolbox > Logic node, drag a Decision step below the Manager Approval step. Connect the two steps. The Decision step generates the outcome lines for each action. In this case, there are three outcomes: Approved, Rejected, and Rework.
      To return to the main Toolbox menu, click the Toolbox icon in the breadcrumb bar.
      Toolbox Icon
      To connect steps, hover over the border of the first step until you see a handle. Click and drag the handle into the second step. Click the canvas to set the line.
      Connect Two Steps
    15. Next, you add a second task step for the Rework outcome. The task recipient is the requester (or originator). In the real world, you might add this step so that the requester can respond to any questions the approver might have. For this demonstration, however, you use this step to launch the form once again so that you can review the attachments list and the files it contains.

    16. From the Toolbox > Basic node, add a Task step and align it with the Rework outcome. Connect the outcome line to the step.
      Rework Task Step
    17. Select the Task step and expand the Configuration Panel. Select the Task tab (if it is not already). For the instructions, enter
      Your request requires rework.
      then for the Actions, enter
      Rework Complete.
      Instructions and Actions
    18. Select the Form tab. For the Form Type, select SmartForm. For the Form, select Leave Requests Form.
      Form Type and Form
    19. The Open Task on a Form wizard launches.

    20. On the References screen, there are no changes. Click Next.
    21. On the Open Task screen, keep the default, Do it for me!. Click Next.
    22. On the summary screen, review the changes K2 makes to the form. Click Save and Finish. When you see the success check, click OK.
    23. Expand the Context Browser and map the Workflow > Workflow > ID property to the ProcInstID parameter.
      Map Workflow ID to Parameter
    24. Select the Recipients tab. The task recipient default is Originator (you!); keep this value.
      Task Recipient
    25. Select the Properties tab. Change the step name to
      Originator Rework
      and collapse the Configuration Panel.
      Rename Step
    26. From the Toolbox > Logic node, add a Decision step and connect it to the Originator Rework step.
      Add Decision Step
    27. Notice you have three outcomes not connected to steps: Approved, Rejected, and Rework Complete. If you were to run the workflow at this point, you would see errors due to the incomplete outcomes. You must add placeholders to each outcome to trick K2 into thinking each outcome leads to a step.

    28. From the Toolbox > Basic node, drag a Placeholder step onto the canvas and align it with the Approved outcome. Connect the line to the step. Repeat this for the Rejected and Rework Complete steps.
      Placeholder Steps
  6. Deploy the workflow. Add Everyone to Start and View permissions. You must have start permissions at a minimum to add and view system SmartObject attachments.

    Before continuing, you just must deploy the workflow to the K2 server. Deploying a workflow publishes it and makes it available for use. If you make any changes to the workflow, you must deploy it again so that the K2 server can register the changes.

    1. Click File > Deploy. You see a success dialog indicating the deployment completed. Next, you adjust permissions so that all authenticated users can start workflows and view reports. The Workflow Attachment SmartObject requires start permissions at a minimum to add and view system-stored attachments. Click the manage permissions... link.
      Deploy Workflow
    2. The K2 Management site launches in a new browser tab.

    3. In the central pane, select the Leave Requests workflow and click Rights.
      Workflow Rights
    4. You assign rights to Everyone, which includes all authenticated users. Click Add. Change the Search scope to All. In the search text box, enter
      everyone
      and click the Search button.
      Search Everyone
    5. In the results pane, you see Everyone. Select Everyone and click Add once again. You now see Everyone in the workflow rights pane. Click Next.
      Add Everyone
    6. Check the boxes for Start and View. Click Finish.
      Start View Rights
    7. Workflow Rights for the Leave Requests workflow are set. Click Close to exit the rights screen. Switch back to the K2 Designer tab in your browser.
    8. Your workflow build is complete for this demonstration. To close the workflow designer, click File > Close.
      Close Workflow Designer
  7. The last configuration is to edit rule actions on the Leave Requests Form for both the Leave Requests (Default) and Workflow Task states. Edit the Leave Requests Form, then use the table below as a guide for configuring the rule actions.
    StateRuleCondition/Action
    Leave Requests (Default)Edit rule: On Leave Request Item, when Save Button is ClickedEdit Action: then start the Leave Requests Workflow (configure)
    Output Mappings: Map the Leave Requests > Leave Requests > Workflow > ID to the Parameters > ProcInstID text box.
    Leave Requests (Default)Edit rule: On Leave Request Item, when Save Button is Clicked

    Add Condition: a control on a View contains a value (if on Attachment Item, File File Attachment contains a value)

    Add Action: Execute a View method (then on Attachment Item View, execute the Add Attachment method)

    (configure): Map the Leave Requests Form > Parameters > ProcInstID to the Input Properties > Process Instance ID text box. Map the Attachment Item > Controls > File File Attachment to the File text box.

    Leave Requests (Default)Edit rule: When the Form is InitializingAdd Action: Hide a View (then hide the Attachment List View)
    Workflow TaskEdit rule: When the Form is Initializing

    Add Action: Add a new action just below then open the Manager Approval worklist item: Execute a View method (then on Attachment List View, execute the Get List method)

    (configure): Map the Leave Requests Form > Parameters > ProcInstID to the Input Properties > Process Instance ID text box.

    Workflow TaskEdit rule: When the Form is Initializing

    Add Action: Add a new action just below then open the Originator Rework worklist item: Execute a View method (then on Attachment List View, execute the Get List method)

    (configure): Map the Leave Requests Form > Parameters > ProcInstID to the Input Properties > Process Instance ID text box.

     Completed Workflow Task Actions
    Workflow TaskAdd new rule: After the Workflow action was submitted

    Add Condition: a control on a View contains a value (if on Attachment Item, File File Attachment contains a value)

    Add Action: Execute a View method (then on Attachment Item View, execute the Add Attachment method)

    (configure): Map the Leave Requests Form > Parameters > ProcInstID to the Input Properties > Process Instance ID text box. Map the Attachment Item > Controls > File File Attachment to the File text box.

    Before you test, you must edit rules on the Leave Requests Form. You add actions to show attachments on the list view when the view loads. You hide the list view on the initial request form (since you do not have any saved attachments yet). You add two actions that save attachments when the requester first submits the form and when the approver submits their decision.

    1. Right-click the Leave Requests Form and select Edit. After the form loads in the designer, click the Rules tab.
      Rules Tab
    2. Notice there are two panes. The left side of your screen contains states while the right side of your screen contains rules. In the following steps, you edit rules for both the Leave Requests (Default) and Workflow Task states.
      States and Rules

      Rules consist of events, conditions and actions. A valid rule contains at least one action.
      • Events define when the rule should run, such as when a button is clicked, or when the form loads. (Events are optional, you can define "event-less" rules that you can call from other rules.)
      • Conditions define whether the rule should run. If the criteria are true, continue the rule, and if the criteria are not met, stop the rule. For example, a condition might evaluate a form to confirm that required fields have content. (Conditions are optional - not all rules will require conditions.)
      • Actions define what the rule should do. For example, show a message, start a workflow, or enable a form field. Rules can contain multiple actions that are run in sequence or in parallel.
      A state represents the configuration and behavior of a form for a specific use. Generally speaking, you configure states for (user) task steps. Each state has its own set of rules which you can edit depending on the task. For example, you use the same form to submit then approve leave requests. You configure the rules for the submit state to enable all fields so you can enter values. You configure the rules for the approval state to disable fields since you do not need to change field values. Rather than creating two separate forms, you can use one form with different states, then apply rules to control form behavior for each of the states.

      The first state you edit is Leave Requests (Default). This is the behavior and configuration for the form used to submit a new leave request. You want to map the ID of the workflow instance for this submittal to the ProcInstID parameter you created. This value is required by the Workflow Attachment SmartObject to save or load records.

    3. Select the Leave Requests (Default) state. Select the On Leave Requests Item, when Save Button is Clicked rule. Click Edit Rule. This is the rule that executes when the leave requester clicks the Save button.
      Edit Save Rule
    4. Locate the action that starts the Leave Requests Workflow. Click (configure).
      Edit Action that Starts Workflow
    5. You have mapped the Workflow ID to the ProcInstID parameter. Now, you map this value to the Leave Requests Form, as the system SmartObject requires this value to save and load records.

    6. Click the Output Mappings tab. In the Context Browser, expand the Leave Requests > Leave Requests > Workflow node. Drag the ID into the ProcInstID text box. Click Finish.
      Map Workflow ID to Parameter
    7. Next, you configure a condition and action that saves the file attachment to the system SmartObject. Click the Conditions tab. Click once on the condition, a control on a View contains a value to add it to the rule definition pane. You want to make sure an attachment exists before you save it. Otherwise, you may save an empty record.
      Add Condition
    8. Click select View and select Attachment Item. The control fills in automatically as there is only one control on the view.
      Select View and Control
    9. Now, you add the action that saves the file to the SmartObject. Click the Actions tab. Click once on Execute a View method to add it to the rule definition pane. Click select view and select Attachment Item View. Click select method and select Add Attachment.
      Execute View Method
    10. Click (configure). Map the Leave Requests Form > Parameters > ProcInstID to the Input Properties > Process Instance ID text box. Map the Attachment Item > Controls > File File Attachment to the File text box.
      Map Input Properties
    11. Click Finish to save the action settings. Click OK to save the rule.
      Add Attachment Action
    12. Next, you hide the Attachment List view when the form loads. There won't be any files saved yet, so there is nothing to show.

    13. Still on the Leave Requests (Default) state, edit the When the Form is Initializing rule.
      Edit Form Initializing Rule
    14. Select the Actions tab (if it is not already). Search for
      hide
      and click once on Hide a View to add it to the rule definition pane. Select the Attachment List. Click OK.
      Hide List View
    15. Next, you add an action that retrieves the attachments for the Manager Approval and Originator Rework steps. Both of these steps use the Workflow Task state as their form behavior and configuration.

    16. Select the Workflow Task state. Edit the When the Form is Initializing rule.
      Edit Workflow Task State Rule
    17. Notice there are two sets of Workflow Activity actions; one for the Manager Approval step and one for the Originator Rework step. For each of the tasks, you want to load the attachments associated with the workflow.
      Workflow Activity Actions

    18. Click once on the then open the Manager Approval worklist item row.
      Select Manager Approval Row
    19. On the left side of your screen, confirm the Actions tab is active, then click once on the Execute a View method action to add it to the rule definition pane. K2 places the action just below the row you selected. If you don't select a row, K2 places the action below all the other actions. If this happens, you can hover over the row until you see a toolbar. Click the up or down arrows to move the action into place. Remember, K2 executes each action in a linear fashion from top to bottom, so placement is important!
      Execute a View Method
    20. Click the select View link and select Attachment List. Click the select method link and select Get List. Click (configure).
      Select View
    21. Map the Leave Requests Form > Parameters > ProcInstID property to the Input Properties > Process Instance ID text box. K2 returns all records with the same process instance ID. Click Finish.
      Map ProcInstID
    22. Select the then open the Originator Rework worklist item row. On the left side of your screen, click once on Execute a View method. Select the Attachment List view and the Get List method. Configure the action by mapping the Parameters > ProcInstID to the Input Properties > Process Instance ID. Your actions should look like the image below. Click OK to save the settings.
      Completed Rule Actions
    23. Next, you add a new rule that saves any attachments the approving manager adds. Select the Workflow Task state (if it is not already). Click Add Rule.
      Add New Rule
    24. Begin with the rule event. With the Events tab active, click After the Workflow action was submitted to add it to the rule definition pane.
      Add Rule Event
    25. Click the Conditions tab. Click once on the condition, a control on a View contains a value to add it to the rule definition pane. Select the Attachment Item view. The control fills in automatically as there is only one control on the view.
      Add Condition
    26. Add the action that saves the file to the SmartObject. Click the Actions tab. Click once on Execute a View method to add it to the rule definition pane. Click select view and select Attachment Item View. Click select method and select Add Attachment.
      Execute View Method
    27. Click (configure). Map the Leave Requests Form > Parameters > ProcInstID to the Input Properties > Process Instance ID text box. Map the Attachment Item > Controls > File File Attachment to the File text box. Click Finish, then OK to save the rule.
      Map Input Properties
    28. Click Finish to save and exit the form.
    29. Check in the form and views. Similar to deploying the workflow, checking in views and forms publishes them to the K2 server and makes the latest version available for use. Right-click the Leave Requests Form and select Check In. When you see the pop-up about associated views, check the box to Check in associated Views. Click OK.
      Check In
  8. Next, you see how the system SmartObject saves and displays multiple attachments from the same workflow instance. Run the Leave Requests Form. Complete the form fields and attach a file. Click the Save button. Open the form from the task notification email the Manager Approval task recipient receives. Attach a file, then select Rework from the actions and submit the form. From your own task notification email (for the Originator Rework step), open the form and review the records in the Saved File Attachments list.
    The Get List method for the Workflow Attachment SmartObject does not return actual files. Therefore, you should only see file details such as the file name, date created, and so forth. One option for returning the actual file is to open a subview and call the Get Attachment method for the same SmartObject. Details on how to do this can be found in the optional Step 11.
    You attach two files for this test. Before continuing, create two sample files using a word editor such as Notepad. Save them to your C: drive for easy access.
    1. First, submit a new leave request. Select the Leave Requests Form and click the Runtime URL found in the central pane. (The Runtime URL is the link to the live form and opens in a new browser tab.)
      Runtime URL
    2. Complete the fields except ID. To attach a file, click the Click here to attach a file link. Navigate to and select your file, then click Open. Click the Save button to start the workflow. (Recall when you configured the Start step, K2 defaulted to the Save button click rule as the event that starts the workflow.) In a real-world process, you would remove or hide any buttons you are not using. This demonstration uses most default settings, which is why you see multiple buttons.)
      Submit Test Form
    3. You might see the screen flash, but there is no confirmation that your form submitted because you did not configure one. If you do not see an error, it is OK to close the form browser tab to continue.
    4. The first step after the workflow starts is the Manager Approver task step. Bob Maggio is the task recipient. (If you are working in your own environment, this is the person assigned the Manager Approval task.) Open K2 Workspace (Desktop) for Bob. Use the User Shortcuts in the lower right corner of your screen to open IE logged in as Bob. Bob is a member of the Finance group. Internet Explorer launches an instance of K2 Workspace(Desktop) logged in as Bob.
      User Shortcuts
    5. Click the Inbox. The Inbox in K2 Workspace (Desktop) displays a list of task notification emails that are waiting action from the logged in user. (In the image below, Bob has three task notification emails. Your screen may be different.)
      Inbox
    6. Locate and click the Manager Approval task notification email.
    7. The Leave Requests Form opens in the central pane. At the bottom of the form (A) is the list of attachments for this workflow instance. There is only one (that you attached when you submitted the form). As the approver, add another attachment. Click the Click here to attach a file link (B) and attach a file. Finally, select Rework from the Actions, and click Submit (C). Make sure you click the Submit button and not one of the buttons on the Leave Details view. (Once again, in a real-world scenario, the buttons are hidden to avoid confusion.) Click OK to close the confirmation pop-up.
      Manager Approval Form
    8. Switch back to the browser with K2 Designer. This is the browser you are logged into (and not Bob). In a new browser tab, open K2 Workspace (Desktop).
      If you do not know how to access K2 Workspace (Desktop), see Accessing K2 Sites.
    9. Click the Inbox. Locate and click the Originator Rework task notification email. This launches the form in the central pane.
    10. Scroll down to the bottom of the form. Notice the Saved File Attachments list now displays the two files that were attached by two different users.
      Attached Files
  9. (Optional) Add a subview to open the attachment file. The Get List method for the Workflow Attachment SmartObject does not return physical files. To open the attachment, you must call the Get Attachment method. One way to do this is to create a subview, then call the method from the subview. Begin by creating an item view from the Workflow Attachment SmartObject. Name it Attachment Subview. Select the fields you want to include (be sure to select File) and select the standard Get Attachment button. On the Leave Requests Form, add a new rule that opens the Attachment Subview when the Attachment List is double-clicked. Map the Attachment List > Workflow Attachment SmartObject > ID to the ID text box. Check in the form and view. Return to one of the task notification emails and refresh the browser. Double-click a list item to open the subview. Click the Get Attachment button to load the file.
    1. Begin by creating a new view. Right-click the System > Workflow > Attachments > Workflow Attachment SmartObject and select Design View. Name the view
      Attachment Subview
      then change the category to Leave Request (or where you are storing your files). Click Create.
      Create Subview
    2. Click Create Labels and Controls.
    3. Select the fields you want to include, making sure you select File. In the Buttons section, check the box to include the standard Get Attachment button. Click OK. Click Finish to save and exit.
      Subview Fields
    4. Next, you add a new rule on the form that calls the subview when you double-click one of the rows on the Attachment List view. Edit the Leave Requests Form.
    5. From the Rules screen, select the Workflow Task state. You want this rule to apply to the form used for the Manager Approval and Originator Rework tasks. Click Add Rule.
      Add Rule
    6. With the Events tab active, click once on When a view raises an event (under the View Method heading) to add it to the rule definition pane. For the view, select Attachment List. For the method, select List item double click. You are executing this rule whenever a row is double-clicked in the attachments list view.
      View Raises Event
    7. Switch to the Actions tab. Now you want to open the subview and pass the ID of the record you double-clicked over to the Get Attachment method. Click once on Open a subview under the Subview Interaction heading to add it to the rule definition pane. For the subview, select Attachment Subview. (Don't worry if the method does not appear next to the subview name. It's OK to continue.)
      Open Subview
    8. Click (configure). Click the Input Mappings tab. Map the Leave Requests Form > Attachment List > Workflow Attachment > ID to the Controls > ID Text Box. You are mapping the ID of the record you clicked as the ID of the subview to load. Click Finish. Click OK. Click Finish to save and exit.
      Map ID
    9. Check in the form and all views.
    10. Return to the K2 Workspace (Desktop) tab in your browser. You should still see the Originator Rework task notification email (because you did not take action on it). Click F5 to refresh your browser. Refreshing the browser updates the SmartForm used to open the task (along with the new subview and rule you just added). Click the email title. The refreshed form opens in the central pane. Scroll down to the Attachment List view. Double-click one of list items.
      Double Click List Item
    11. The subview opens. Click the Get Attachment button. The view loads the selected record. Notice now, you can click the File and open it.
      Subview with Attached File
Review

You often see attachments saved during a workflow task, to a data source associated with the form. While this is sufficient for most scenarios, in some cases, you may want to work with all the attachments saved during the entire workflow instance. Use the Workflow Attachment system SmartObject to add and view attachments at the workflow level. In this way, you can manage attachments from a workflow (start to finish), regardless of the task assignment or form.

To learn about adding and viewing comments using a system SmartObject, see How To: Add and View Workflow Comments.