SharePoint 2007 Workflows - Adding a user input form

Posted on 7/9/2008 @ 12:17 AM in #SharePoint by | Feedback | 38328 views


Table of Contents for on SharePoint 2007 WF Authoring using Visual Studio.

1. Setting up your environment for writing VS2005 workflows.

2. Writing an ultra basic workflow, deploying it, and slicing dicing how it worked.

3. Making that workflow more complex, adding if/else, and a bunch of activities that sort of make it more interesting.

4. Adding user interaction to that workflow using Infopath forms.

5. Authoring SharePoint 2007 Workflows using VS2008.

So far, in writing about writing sharepoint 2007 workflows in visual studio 2005, I have talked about setting up your environment, writing an ultra-basic WF where I demonstrated how the workflow project works. I then enhanced that example to include some branching logic to give an idea how what it is like to author a real world workflow. In this blogpost, I will enhance the previously written worklows, to include an input form.

Now, as you can see, the previously written roll of dice WF automatically picks the logged in user as the originator of the workflow, and creates a task for the originator.

Well, what if I wanted to play (roll dice) on someone else's behalf. In other words, what if I wished to be able to use an intiatiation form, and everytime the workflow started, it could ask me "Who are you playing on behalf of".

So - whenever the workflow starts, it needs to ask me for some data. Sounds like I need to create an "Inititiation Form".

Here is a complete list of the various forms a WF can use -

a) Association form - this pops up when a WF is associated with a list.

b) Initiation form - this pops up when a WF is intiated on a list item.

c) Modification form - you'd use this WF to perform a modification on the WF.

d) Task form - this can be used to substite for the task created for the WF.

The concepts between all 4 are portable, so I will move ahead with my canonical roll of dice example, and demonstrate, how to add an inititiation form to my existing WF. Here goes.

  1. Create the Infopath Form
  2. Publish the infopath form
  3. Modify your workflow.xml, so the WF can actually use the form.
  4. Modify your code, so the form's data is accessible via code.
  5. Deploy, Execute, and Play

Let us walk through these steps one by one. BTW - I am going to assume now that you are somewhat familiar with infopath. If you aren't - I'd recommend reading this article first, and establishing a general comfort feel with infopath first.

1. Create the infopath form

Start infopath and create a form that looks like as shown below -


The two controls you see there are a drop down combo box, and a button. Go ahead and right click on the drop down box, and go to "Properties". Change it's name to "assignee".

Under the "List Box Entries" area, choose the radio button that says "Look up values from an external datasource". Naturally since you don't have any datasources yet, you will need to click on the "Add" button to create a datasource. Go ahead and add a datasource to "receive" data from a sharepoint list. Under the SharePoint site details, add http://moss2007 (or whatever your sharepoint site is), when prompted to pick a list or library, choose "User Information List", and when prompted to pick the relevant columns, pick atleast the "Account" column.

When the datasource is added, and you are back in the infopath --> assignee properties, click on the button next to entries, and choose "Account" as the field you wish to show for the drop down box. When all is done, your drop down properties should look like as below:

Next - you need to configure the button.

Right click properties on the button, and change it's title to "Go Play!!". Click on the "Rules" button and add two rules

a) To submit the button to a new data connection. This will require you to create a new data connection, this time to "Submit", to the "Hosting Environment". Call this data connection "Submit".

b) Close the form.

Now that your form is authored, next you need to publish it.

2. Publish the form

While still in infopath, go to Tools --> Form Options. Under there, go to "Security and Trust" and change the trust level to "Domain" (if you are working in a domain), or "Full Trust" (if you don't have a domain handy). The better approach is to use digital signatures anyway.

With the trust fixed, click on "Publish form template" under Design tasks, and go through the following steps

a) Publish to a network location (the feature will take care of putting it on sharepoint).

b) Form template and pathname - publish it to a file called "InititationForm.xsn", and put it at the same location as the "feature.xml" and "workflow.xml" files are.

c) In the next screen, CLEAR OUT that textbox (Yes, clear it out, and ignore the warning)

d) Publish the form.

3. Modify your workflow.xml, so the WF can actually use the form.

Okay great, now we have added an instantiation form, we need to re-add in the instantiation form elements we took out in Ultra Basic WF.

Go ahead and modify your workflow.xml, so it looks like this -

<Elements xmlns="">



       Description="This workflow allows for roll of dice"



       CodeBesideAssembly="RollOfDiceWF, Version=, Culture=neutral, PublicKeyToken=788572d21f3ea9ad"





    <!-- Tags to specify InfoPath forms for the workflow; delete tags for forms that you do not have -->







Now, the InstantiationURL seems pretty straightforward. What the hell is that Instantiation_FormURN?

Well, that is a unique way of identifying the infopath form. And you can get that string, by opening the published form in design mode, and going to File -->Properties.

4. Modify your code, so the form's data is accessible via code.

Now, while your published form is still open in design mode, click on File --> Save as Source Files .. and save to a scratch area. This will cause infopath to save a bunch of files, the one we are interested in here is "myschema.xsd".

Run the following command, to generate a myschema.cs out of the xsd.

xsd.exe myschema.xsd /c /o:.

Now, add the myschema.xsd to your project.

Great, now we can summon the unlimited power of the XmlSerializer to extract initiation data out of our WF Form. Go ahead and modify the createTask1_MethodInvoking event method to as below -

private void createTask1_MethodInvoking(object sender, EventArgs e)


    createTask1_TaskId1 = Guid.NewGuid();


    XmlSerializer serializer = new XmlSerializer(typeof(myFields));

    XmlTextReader rdrMyFields = new XmlTextReader(new System.IO.StringReader(workflowProperties.InitiationData));

    myFields fields = (myFields)serializer.Deserialize(rdrMyFields);

    createTask1_TaskProperties1.AssignedTo = fields.assignee;


    // createTask1_TaskProperties1.AssignedTo = workflowProperties.Originator;


    createTask1_TaskProperties1.Title = "Congratulations, thou art ye winner!";

    createTask1_TaskProperties1.Description = "You have won!!! Now go and claim your prize";

    createTask1_TaskProperties1.SendEmailNotification = true;


Great! As you can see, rather than hardwiring the originator of the workflow to the "AssignedTo", instead now I am pulling that out of the XmlSerializer/Infopath form. w00t!

5. Deploy, Execute, and Play

Now this is the easiest step. Hit F5.

As usual, go to a list, associate this WF, and start this WF, and VOILLA - you are presented with an infopath form, running in your browser when you instantiate the workflow, as shown below -

Now, our WF works well and fine, but what is "cfranklin" doing in a MOSS Workflow?

Oh that's a secret that I'll reveal in a couple of weeks.

Until then - sayonara! and hope you enjoyed this series on SharePoint 2007 WFs.

Sound off but keep it civil:

Older comments..

On 8/30/2007 10:52:06 AM Peter {faa780ce-0f0a-4c28-81d2-3667b71287fd} said ..
Carl just mentioned you in his DNR show today so it's not such a big mystery anymore :)

On 8/30/2007 11:06:28 AM Sahil Malik said ..
LOL - okay I guess the cat is outta the bag then :). w00t!


On 8/30/2007 11:39:14 PM Alana said ..
Hi Sahil,

When I'm retrieving user information from sharepoint in a drop down list and publishing the form up into sharepoint, it makes the list scrambled. Names are not in alpha order and NTAUTHORITY accounts appear also.

All I want is a drop down list of user names in alphabetical order. I have searched high and low for an answer to sorting the drop down list but have not found any answers. Can you help?


On 9/13/2007 4:00:55 AM Jess said ..
What if you don't want your users to add documents, upload files, but you want them to respond to surveys?

On 10/4/2007 3:32:06 AM Khaled Riyal said ..
Hi Sahil,

I made these steps and the workflow works only when it is set to be started manually, but when i set it to be started when a new item is created i get an error occured, what do you think is the problem?


On 10/10/2007 10:57:23 AM Suhaib said ..
With iniation form you need to run the workflow manually.

On 10/17/2007 7:31:07 AM Urko said ..

I am experiencing a problem and it's that when i start the workflow, the infopath appears closed, so i can't do anything.

can you tell me how to configure the <Instantiation_FormURN>urn:schemas-microsoft-com:office:infopath:InitiationForm:-myXSD-2007-08-26T01-34-04</Instantiation_FormURN>

because i don't know where to find this in my computer...


On 11/13/2007 11:35:54 PM gynette said ..
i have follow the steps above and there is no errors but it does prompt me to input.

Task list is empty. Which steps i have miss out? pls help... thanks..

On 11/14/2007 9:34:04 PM gynette said ..

After compile, there is no errors appear and it does not prompt me for form input.

I make a catch in the xml (getting data from infopath), it show errors as below:

System.ArgumentNullException: Value cannot be null.

Parameter name: s

at System.IO.StringReader..ctor(String s)

at RollOfDiceWF.Workflow1.createTask1_MethodInvoking(Object sender, EventArgs e)

Pls help..

On 12/11/2007 12:07:30 AM chris said ..

i am also facing some of the problems that users have mentioned above. But am not sure why there is no reply from ur side!

On 2/17/2008 12:04:38 PM Elievl said ..

The part between the Instantiation_FormURN-tags can be found in infopath:

Open the form in design mode, go to file - properties.

You will find it in the ID box.

On 2/28/2008 4:06:26 PM Jason said ..
I am not sure where the myFields type is comming from and I do not seem to have it in my project. Any suggestions as to what I may be missing?

On 3/5/2008 12:51:39 PM Jason said ..
I found the solution to my own problem. I had renamed myFields in the InfoPath form, which then changed the class name in the myschema.cs file that was generated.

On 3/10/2008 3:48:02 PM IT-Dev wdrożenia Sharepoint said ..
Ping back from Elektroniczny obieg dokumentów, wdrożenia Sharepoint

On 4/5/2008 10:38:22 AM Yaman said ..
Hi Sahil,

I followed these steps precisely, if the result is above 3 ... I am getting an "Error Occured" message, and the report does not show any extra informarion. When debugging everything goes fine, but at the end I get the result "Error Occured", so what do you think this error in this case. I also tried to disable the email notification, same result.

By the way, below 3 everything runs ok.

On 4/9/2008 2:49:26 PM Lakshmi said ..

I get the same error.

System.ArgumentNullException: Value cannot be null.

Parameter name: s

Did anybody find a solution to it.

Please let me know


On 5/6/2008 3:50:11 AM Law said ..

I also get the same error.

System.ArgumentNullException: Value cannot be null.

Parameter name: s

What could we did wrong?

On 5/7/2008 12:56:43 PM Tim Stewart said ..
Thanks for the great tutorial!

On 6/13/2008 4:00:10 AM gwen said ..
hi, thanks for the tutorial!

but my form does not appear. i already get the standard view for tasks......

i followed all the steps.

do you have an idea?


On 9/11/2008 9:40:22 PM roberto said ..
I've got the same problem... for me the fix was to enable the web-browser enable option in Form Options.

My Log error message was "This form cannot be opened. it is not workflow enabled"

this might help|

On 11/25/2008 4:03:38 PM Deven said ..
I have list in MOSS 2007, For example:list contains Emp ID, Emp Name, Emp Dept. When i will click on Emp ID link in List row, then Infopath should popup with selected row information.

User can modify information in Infopath (Except Emp ID) and again save all information in another list.Please provide solution how can i achieve?

On 1/6/2009 10:21:14 AM Pieter said ..
Nice tutorial.

Just one question. From where did you get this: InstantiationUrl="_layouts/IniWrkflIP.aspx"

Cause you have a lot different kind of URLs. You know what they mean?


On 1/19/2009 9:29:44 AM sandeep said ..
I also got the same "Error Occured" option while starting the workflow. I followed the steps very precisely. Only thing which I eliminated was that TaskContentTypeID in previous posts..

Does anybody found the solution ???


Sandeep Dh

On 1/19/2009 9:47:12 AM sandeep said ..
During debugging, I found out the splistitem.file was returning null.

On 2/6/2009 8:10:56 AM Prakash said ..
I get the same error.

System.ArgumentNullException: Value cannot be null.

Parameter name: s

Did anybody find a solution to it.

Where is the guy who posted it ?

Please let me know


On 3/18/2009 3:14:21 PM MG2005 said ..
Great series!!!

On 7/21/2009 3:07:50 AM Hari said ..
Hi Sahil,

I followed all the above steps. but i am getting "The form has been closed" when i run the workflow. Can you please tell me wat will be the problem?


On 10/20/2009 2:50:24 PM Rob said ..
I know this is a very old post, but can you re-post it? I'm having trouble seeing the images for each step. thanks.

On 11/3/2009 8:52:03 AM Rana said ..
I have also followed all the steps. but i am getting "The form has been closed" when i run the workflow.

Help is needed in this regard..



On 1/9/2010 7:27:25 AM Bruce McGowan said ..
I am a new end-user of Share point at a company that is a new client of Sharepoint. I have a problem that my administrator is having problems with. I have all the "permissions" to contribute to surveys created by our corp-office. There is one common-field, on my input screens that does not function properly. The drop down box to enter my plant location appears to have a different character width than all the other users in our plant. The drop down appears to have a 3-4 character width and no visible data in the drop-down. How does this appear as such for a single user. Does it appear a permission ,is missing an obscure, put important, feature?

On 1/21/2010 1:34:19 AM Rahul Vartak said ..
Hi All,

Im also facing the "The form has been closed" error message when i run the workflow.

I made sure the form was browser enabled and deployed along with the workflow project.

Any ideas for the causes of this message would be very helpful.


On 2/10/2010 1:17:53 AM Ashok said ..
In step 4 it is mentioned to generate the .cs file from myschema.xsd. But only the addition of myschema.xsd is mentioned. What is the importance of generating the .cs file if we are not going to include the same in project.

Also in step it is mentioned that to publish the form to location where the feature.xml and workflow.xml files are located. Will the form be included as a part of package by default since it is present with the xml files.

On 7/16/2010 4:44:25 AM Pradipta said ..

thanks for your nice article .I finished all the thing and deploy and add the work flow to a custom list but when i click new it only open the default content type not the infopath form can please help me...

On 7/28/2010 2:56:00 AM Jameel said ..
Hi Sahil,

As like Pradipta when i click new it only opened the default content type not the infopath form....

Please respond on this

Please find some time to reply....


On 10/22/2010 6:00:42 PM Cory said ..
For the "Form has been Closed" message, the log always reflected that "The specified form cannot be found". The feature.xml element manifest should include the published .xsn. For example:


<ElementManifest Location="workflow.xml" />

<ElementFile Location="InitiationForm.xsn"/>