views:

516

answers:

1

How do I access the data passed back from a workflow association form?

Scenario: When an admin associates a workflow with a sharepoint list I want to display a infopath form that allows variables to be set that apply to all instances on that list. The association form comes up as I would expect and it submits the data entered back to the hosting environment. I've read that I can get to the data once inside an instance workflow through SPWorkflowActivationProperties.ActivationData but this is an xml string. Is it not possible to access the returned data through extended properties much like what you do with normal infopath forms?

+2  A: 

As far as I know this doesn't seem possible using InfoPath OOTB. However most of my experience with custom initiation forms used ASP.NET web forms where we serialized a class and stuffed it into ActivationData.

Possible approaches might be:

  1. Encapsulate XML parsing

  2. Use xsd.exe to create a class based off the schema of your infopath form.

1. Encapsulate XML parsing

You could create a class that encapsulates your form data and takes the xml string as a parameter of it's constructor.

Infopath form:

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.2" productVersion="12.0.0" PIVersion="1.0.0.0" href="file:///C:\Documents%20and%20Settings\Administrator\My%20Documents\Template1.xsn" name="urn:schemas-microsoft-com:office:infopath:Template1:-myXSD-2005-10-21T21-12-27" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?><my:assetTracking 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/2005-10-21T21:12:27" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-gb">
<my:employee>
 <my:employeeName></my:employeeName>
 <my:employeeDepartment></my:employeeDepartment>
</my:employee>
<my:assets>
 <my:asset>
  <my:assetID></my:assetID>
  <my:assetDescription></my:assetDescription>
  <my:assetMake></my:assetMake>
  <my:assetModel></my:assetModel>
  <my:assetSerialNumber></my:assetSerialNumber>
  <my:assetAssignedTo></my:assetAssignedTo>
  <my:assetDepartment></my:assetDepartment>
  <my:assetLocation></my:assetLocation>
  <my:assetCategory></my:assetCategory>
  <my:assetNotes></my:assetNotes>
 </my:asset>
</my:assets>

Custom form data class

public class FormData
{

  public string EmployeeName { get; set; }
  public string EmployeeDepartment { get; set; }

  public FormData(string formData)
  {
       XmlDocument document = new XmlDocument();
       document.LoadXml(formData);
       XmlNamespaceManager namespaceManager = new XmlNamespaceManager(document.NameTable);
       namespaceManager.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-05-08T04:21:20");

       // Initialize member fields
       this.EmployeeName = document.SelectSingleNode("/my:employee/my:employeeName", nsmgr).InnerText;
       this.EmployeeDepartment = doc.SelectSingleNode("/my:employee/my:employeeDepartment", nsmgr).InnerText;

       etc....
  }
 }

2. Use xsd.exe xsd can be used to generate a class that is based on the schema used by your workflow form. See: How to: Access Association and Initiation Form Data in a Workflow

Edward Wilde