Subscribe to News feed

Dynamically selecting an InfoPath PDF Conversion View from a SharePoint workflow

Posted at: 17:21 on 31 October 2012 by Muhimbi

View SelectionOne of the more popular features of the Muhimbi PDF Converter for SharePoint is the ability to control which view or views to convert to PDF. It is even possible to specify which views to convert depending on the current status of the form.

The views to convert can be specified during design time, or at run time using a little bit of custom code or InfoPath rules. However, we are asked quite frequently about how to control which view to convert using a SharePoint workflow. The example provided below uses a SharePoint Designer workflow, but it works equally well in Nintex and Visual Studio workflows.

 

Creating the InfoPath form

  1. Open InfoPath 2010 Designer.
  2. Select Blank Form / Design Form.
  3. Change the title at the top to 'View 1'.
  4. Create a Text box and name it '_MuhimbiViews'.
  5. On the 'Page Design' tab select 'New View'.
  6. Name the new view 'View 2'.
  7. Change the Title at the top to 'View 2'.
  8. From the ‘File’ menu select 'Publish to SharePoint Server'.
  9. Enter the location of your SharePoint site collection.
  10. In the 'What do you want to create or modify' tab accept the default settings (Form Library).
  11. Accept the default for 'Create a new form library', we named it 'MuhimbiViews', but it can be anything.
  12. On the next screen make the '_MuhimbiViews' field available as a column on the library and select 'Allow users to edit data in this field...'
  13. Finish the publishing process.

 

(There are multiple ways to set InfoPath fields from a workflow, see this article for more details).

 

Initial Test

To test that all steps have been carried out correctly and that the PDF Converter is working as expected carry out the following steps:

  1. Open the new Form Library in SharePoint and fill out a new form. Don’t enter any data, just save it.
  2. Convert the file that was just generated from the context menu. When the PDF is opened you'll see View 1.
  3. Fill out another form, but this time enter 'View 2'. Save it under a new name.
  4. Convert the file we just generated from the context menu. When the PDF is opened you'll see View 2.
     

 

Creating the workflow

  1. From the Library ribbon in SharePoint select Workflow Settings / Create a workflow in SharePoint Designer.
  2. Name the workflow whatever you like, we named it 'Muhimbi Views'.
     

In this workflow you will need to set the value of the _MuhimbiViews field before carrying out the conversion. The problem
is that the workflow does not persist the value of the changed field before executing the Conversion step, so we need to trick SharePoint a bit, not uncommon.

There are two ways to trick the workflow:

 

Option 1 - Using an Impersonation step

  1. Position the cursor before Step 1 and click the 'Impersonation Step' button in the ribbon.
  2. Position the cursor inside the Impersonation Step and add a 'set field in current item' action.
  3. Use this action to set the value of the ‘_MuhimbiViews’ field to 'View 2;View1'. (Note that when the field was exported it probably defaulted to a different name, e.g. ‘Muhimbi Views’, it is mapped correctly internally though)
  4. Position the cursor after the Impersonation Step and click the ‘Step’ button to add a new step.
  5. In this new step add the 'Convert Document' action and fill in the blanks.
  6. Publish the workflow and execute it on a previously filled out form.
     

The resulting PDF should contain views 2 and 1 (in that order)

 

Option 2 - Using 'Pause for duration'

The steps below assume the default, empty, workflow state. Not the workflow entered as part of Option 1.

  1. Position the cursor inside the first Step and add a 'set field in current item' action.
  2. Set the value of the ‘_MuhimbiViews’ field to 'View 2;View1'
  3. Add the 'Pause for duration' action as the next step and let it pause for 1 minute (it may actually take 5, but that can be tweaked).
  4. Add the 'Convert Document' action and fill in the blanks.
  5. Publish the workflow and execute it on a previously filled out form.

 

It may take a while to execute due to the Pause action, but the resulting PDF should contain views 2 and 1 (in that order)

 

A third option exists, which is to specify Converter Specific Settings using the XML Override facility in the Convert Document Workflow activity. For more information see this example (scroll to the top of that page for an introduction).

 

That is all. Any questions or comments? Use the feedback facility below or contact us directly.

Labels: , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

Need support from experts?

Access our Forum

Download Free Trials