Dynamically selecting an InfoPath PDF Conversion View from a SharePoint workflow
One 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
-
Open InfoPath 2010 Designer.
-
Select Blank Form / Design Form.
-
Change the title at the top to ’View 1’.
-
Create a Text box and name it ’ _MuhimbiViews’.
-
On the ’ Page Design’ tab select ’ New View’.
-
Name the new view ’View 2’.
-
Change the Title at the top to ’ View 2’.
-
From the ‘ File’ menu select ’ Publish to SharePoint Server’.
-
Enter the location of your SharePoint site collection.
-
In the ’ What do you want to create or modify’ tab accept the default settings ( Form Library).
-
Accept the default for ’ Create a new form library’, we named it ’ MuhimbiViews’, but it can be anything.
-
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…’
-
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:
-
Open the new Form Library in SharePoint and fill out a new form. Don’t enter any data, just save it.
-
Convert the file that was just generated from the context menu. When the PDF is opened you’ll see View 1.
-
Fill out another form, but this time enter ’ View 2’. Save it under a new name.
-
Convert the file we just generated from the context menu. When the PDF is opened you’ll see View 2.
Creating the workflow
-
From the Library ribbon in SharePoint select Workflow Settings / Create a workflow in SharePoint Designer.
-
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
-
Position the cursor before Step 1 and click the ’ Impersonation Step’ button in the ribbon.
-
Position the cursor inside the Impersonation Step and add a ’ set field in current item’ action.
-
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)
-
Position the cursor after the Impersonation Step and click the ‘ Step’ button to add a new step.
-
In this new step add the ’ Convert Document’ action and fill in the blanks.
-
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.
-
Position the cursor inside the first Step and add a ’ set field in current item’ action.
-
Set the value of the ‘ _MuhimbiViews’ field to ’ View 2;View1’
-
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 )).
-
Add the ’ Convert Document’ action and fill in the blanks.
-
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.
Clavin is a Microsoft Business Applications MVP who supports 1,000+ high-level enterprise customers with challenges related to PDF conversion in combination with SharePoint on-premises Office 365, Azure, Nintex, K2, and Power Platform mostly no-code solutions.