Jan 25, 2010

Default values for association Infopath forms in Sharepoint workflows

At first, I thought you could set default values for an association form directly from the Infopath tool, simply assigning default values to the fields. That works, but the association form state gets lost after the user submits the form.

The correct way is creating an AssociationData element in the workflow.xml file of the workflow and the format is identical to the string passed into your workflow in the workflowProperties.AssociationData variable (minus some backslashes and carriage returns that might be present in the string).

In the example, my root data group in Infopath is called WorkflowParameters and inside I have two text fields, HorasRetraso and EmailBody (ignore the bilingual craziness). And we create a similar structure in the workflow.xml file.

Here's an example:

Infopath data design:




workflow.xml
file

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Workflow
Name="Workflows.ViajesCuestionario"
Description="My SharePoint Workflow"
Id="6dcb00c0-29af-448b-a5cd-333781c6071c"
CodeBesideClass="Workflows.ViajesCuestionario.Workflow1"
CodeBesideAssembly="Workflows.ViajesCuestionario, Version=1.0.0.0, Culture=neutral, PublicKeyToken=17d9b5dddc2775a2"
AssociationUrl="_layouts/CstWrkflIP.aspx">

<Categories/>
<AssociationData>
<my:WorkflowParameters xml:lang="es-ES" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-09-30T09:09:24" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003">
<my:HorasRetraso>48</my:HorasRetraso>
<my:EmailBody>&lt;html&gt;&lt;body&gt;A link in the email body &lt;a href=&quot;http://www.google.com&quot;&gt;Link Text&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;</my:EmailBody>
</my:WorkflowParameters>
</AssociationData>
<MetaData>
<Association_FormURN>urn:schemas-microsoft-com:office:infopath:WorkflowViajesCuestionarioAssociation:-myXSD-2009-09-30T09-09-24</Association_FormURN>
<StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>
</MetaData>
</Workflow>
</Elements>



No comments:

Post a Comment