>Using Contact Selector in a Modification InfoPath Form


>

As always things are never as simple as you thought they would be. This post is a case in point, so I have been building a workflow which allows a user to approve a list item. This workflow is built with VS2005 and with previous workflows, the modification forms have worked beautifully.

Well that is until I wanted to include the contact selector inside the modification form. As I mentioned the workflow allows a user to approve the list item, however what if the user is away or want someone else to approve it. Well then a simple workflow modification should sort that, shouldn’t it?!

In order to create a workflow modification you need to do the following:-

  1. Create a form to use for your modification
  2. Update the workflow xml with a modification tag which has a unique GUID and contains the URN of the form that the workflow is going to use.
  3. Implement a EnableWorkflowModification which references the GUID that it is modifying, this is the part where the problem existed (more on that later).
  4. Implement a Event Listener activity so that when the modification occurs there is something listening for it!
  5. Finally implement the handler which updates the workflow and related objects so that the modifications are made.
We will not cover points 1 and 2 as they are discussed in this great post ([insert url]).

So starting with point 3 firstly, so what does an EnableWorkflowModification activity do?

Well it should log that the modification has been activated, it also then assigns the default data that should past into the modification form. Now this is the interesting part, how do you make the xml form data that the InfoPath form requires?

Using a tool called xsd which is part of the VS2005 toolkit. Basically with every InfoPath form there is a XML schema created (.xsd file) if we call xsd /c with the path of the XSD then a code class will be created which is used for serialization/deserialization.

This is used within the EnableWorkflowModification activity to generate the xml ContextData which is then loaded into the Modification form.

In our example we use the serialization class to create a class of the form and then assign values to the various properties of the class. We can then serialize this class to make the xml.

This would be achieved like so:-

ReassingForm reassignForm=new ReassingForm();

reassignForm.ReassingComments = "The workflow is being reassinged from " + m_sApproverLogin;
reassingForm.Approver = ApproverArray;

Here we are assigning the current approver and also uploading some comments to the form, which the user can then update as required.

Finally the class needs to be serialized :-

Now when the workflow modification kicks in then a user gets a link in the workflow status page allowing them to perform the modification. When this is clicked then the Context Data is loaded into the InfoPath form and the InfoPath form is displayed.

When the contact selector is used an error will occur complaining about the fact that the my namespace prefix is not found. So how do we get around this?

We need to tell the serialization method that it should add my prefixes so the xml instead of being like this :-

is like this:-
To do this we need to use the XmlSerializerNamespaces class.
This would look like:-

XmlSerializerNamespaces nsReassignForm = new
XmlSerializerNamespaces();
nsReassignForm.Add(“my”, “http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-05-29T12:53:57“);

and can be used when calling XmlSerializer.Serialize as additional parameter.
This will then fix the error on form and allow the contact selector to be able to process and store the users that you have provided.

Let me know how you get on.

>SharePoint Workflow InfoPath Forms: SchemaValidationException, Exception Message: Schema validation found non-datatype errors.


>Whenever I start developing SharePoint workflows there are always a couple of gotchas that get me. Unfortunately or should that be fortunately it is generally different things each time.

The current workflow that I am developing for a client is using Association and Initialisation Forms. Getting the association form to work took a couple of attempts, the major one being that each time I updated the solution, the forms themselves were not being updated which kinda didnt help as I was trying allsorts of things to solve it. Once the solution was deleted and readded in then the form started work.

“Great I thought” and then I actually tried to start a workflow and the dreaded Form has closed message quickly appeared.

Fortunately on a quick investigation of the ULS logs (c:\program files\common files\microsoft shared\web server extensions\12\logs) there was an entry from the Form Server Runtime. Which stated that the form could not be open successfully due to the following:-

SchemaValidationException, Exception Message: Schema validation found
non-datatype errors.

Looking around on the web there wasn’t too much however I did find a post by Scot Hillier on creating a workflow with such forms. This pointed me to something that I wasn’t do and this is using Association Data. When you create an InfoPath project then a sampledata.xml file is created which gives a – yes you guessed it – a xml file with the sample default data from your form.

Using this I created an entry within workflow.xml called AssociationData. Using the sampledata.xml copy over the xml in between the AssociationData tags.

Redeploying the solution refreshed the InfoPath forms but the Initialisation form still failed to load.

Looking at the form schemas I realised that maybe it was due to the difference in the forms schemas. I updated each of the elements, each time there was no difference until finally I updated the root element schema name so that they are the same.

This solved the problem, on top of that it meant that I now only needed one serialization class to read the forms xml data! If you don’t know what I am talking about then please take a look at this MSDN post.

Happy coding.