Use InfoPath form in Workflow


Hi everyone,

Today I’ll talk Workflow with InfoPath , especially the steps needed to attach the form to a task.

Step 1: Creating the module

First start by adding a module called “Forms” in our workflow in order to have a solution that looks like this.

Step 2: Add the InfoPath form to the module

Then create our infopath.

Nothing complicated here, the idea of this article is just to show how to integrate ourcustom form in a SharePoint task.

Once the form is done, a modification of the loan security is necessary, for this we must go the menu “File” – “Form Options”

Here we need to specify security at least on “Domain”.

Once this security in place, publish our form. We will publish it directly into our project.For this we must go to the tab publication and choose to publish on the network.

Select the location of our module “Forms” that we created in our workflow.

The next step is very important, we must empty the link to access our form!

This generates an error message when clicking next, click “OK” to ignore.

Let’s get to publish the form.

Once the form is published, get back to our Visual Studio solution and display all files by clicking the appropriate button.

Do a right click on our infopath to add it to the solution.

We can see in the Elements.xml file thath the form has been automatically added to the module.

Step 3: Edit the “feature.xml”

Now that infopath is added, we must deploy it to our SharePoint environment. For this we must add a specific receiver in the manifest of the feature.



ReceiverAssembly = "Microsoft.Office.Workflow.Feature, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"

ReceiverClass = "Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver"

That’s this receiver which will upload the infopath. We must also specify the following property so it knows where to look for forms.



<Property Key="RegisterForms" Value="Forms\*.xsn"/>

In the end we have a manifest that looks like this

Step 4: Edit the workflow’s “Elements.xml” file

We now need the ID of OOB content type “SharePoint Workflow Task InfoPath” in our definition.



<Workflow …

TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160" >

We must also specify the urn of our infopath. Caution! Make sure you have the urn of the published form!



<Task0_FormURN>urn:schemas-microsoft-com:office:infopath:Task1:-myXSD-2012-04-26T13-02-48</Task0_FormURN>

For each form you can specify the ID here the example “<Task0_FormURN>” shows the ID 0, remember this ID we will use it right after!

Ultimately our file “Elements.xml” should look like this

Step 5: Changing the code to create the task.

In our workflow we can now specify the form that we use, for that we must change the properties of the task by giving the ID of the appropriate form, in our example we will give him the ID 0.

Our code looks like this

Step 6: Checking.

After deploying the solution we should find our form in the central administration more precisely in “General Application settings” – “Manage form templates”

And indeed it is present.

By starting our workflow when creating the task we can see our form!

Voila !

Christopher.

Advertisements
This entry was posted in SharePoint 2010 and tagged , , . Bookmark the permalink.

26 Responses to Use InfoPath form in Workflow

  1. Bjoern H Rapp says:

    Hi Christopher, thanks for a well written and easy to understand Workflow-InfoPath tutorial. InfoPath especially has been a dark area for me, but things are a lot clearer no
    Regards Bjoern

  2. Thank you, I’m glad this was helpfull!

  3. Michael says:

    I am doing this exact same thing, the timing on your post is perfect! One question, do you know if the publish location can be another fileshare and then the xsn file copied to another location for inclusion in a project? That’s the only difference I have from yours but when I click on my task, I still get the OOTB task form. My task content type is derived from one of the OOTB task content types but that should not matter in this case.

    • Hello Michael,
      Yes your publish location can be somewhere else, here I publish the form on the solution for “speed” reason. If it’s included on the correct place in your project (in the module) it should be ok.
      Can you check if your form is visible in the central administration? if yes the trouble is elsewhere. Be carefull with the content type derivation, I had some trouble with custom task content type within workflows, my workaround is to use OOB task content type and add other needed column to the task list.

      • Michael says:

        Great, thanks. I don’t have any additional fields in my case, I just created the CT derivation to get the custom form but it looks like I can achieve what I need based on your post – override the task edit form for the OOTB type with my custom form.

  4. Michael says:

    It’s wierd, I changed my TaskListContentTypeID to be the OOTB collect signatures approval task (that’s the form I based mine on). I have the task URN set for each task in my WF but for some reason, it still just reverts back to the OOTB form. Have you seen this before?

  5. Michael says:

    Just tried and if I use that, it does render the right form but it’s missing data on the form (requestedBy, Due Date, etc.) At least this validates that my form is deploying OK but looks like I need to dig some more. Thanks so much for your help, I really appreciate it!

  6. Heerak says:

    Hi Cristopher,

    We have implemented the same way and form is working fine.
    but now we want to make some changes to the form.
    can you help me how to edit already created infopath form.

    Thanks,
    Heerak

    • Hello heerak,

      Have you tried to get a copy of the published form? I think you can find some “how to” on the web, I found this one : http://office.microsoft.com/en-us/infopath-help/modify-a-published-form-template-HP010103091.aspx hope this will help you.

      Christopher.

      • Heerak says:

        Hi Christopher,

        I did the same way shown in this article but when i try to run workflow, it says form missing. when i checked and found that form in missing from form template library in central administration. I undo my changes and re deploy and i can get last working form back in template library.
        Can you help me in this.

      • Hello,

        So you have a form that is working, when you try to update the form it’s not working anymore saying that the form is missing. I did’t understood if you have checked if the form is present on the library, if yes, are your sure that the urn you filled are correct? if not are your sure your form is on your new wsp?

      • Heerak says:

        Hi Cristopher,

        I have a form which is running fine right now.
        I have a date field which i want to make as default to today.
        so i have to update form.
        I have working copy in TFS, i take a copy of that made changes and re published it on network location as TFS location.
        Now this form is checked out in my TFS.
        Now i deployed my wsp to application and when i try to run that form it says fail to retrive.
        i checked form library in centarl administration and saw that form is missing from there which was there before.
        I then undo my change in TFS and re build and redeploy solution , i can see last form again in form library in CA, and form is working fine as usual as before.

        Can you help me now. If i am missing any thing here.

        Thanks,
        Heerak

      • Hello Heerak,

        Are you sure that your form is well formed after your modification? the first thing I think about is that your form has error. Can you try to add a simple text in your form and redeploy it again for test?

    • meena says:

      Heerak,
      u can deactivate your workflow feature, redeploy the wsp adn activate the feature again. check the form published time in the central administration > form templates.

  7. N Reddy says:

    Hello Everyone,
    I am looking something like how to get current running workflow library / list information into the custom task form which you explained here. i tried using some code but form is not coming up. Not only that i observed when you try any custom code it is doing the same. please any help.

    My scenario is on custom task form i need to show some infopath information which is published to form directory. Thanks Narayan

  8. Hello Narayan,

    Can’t you get this information from “WorkflowProperties” ? I

  9. meena says:

    Hi Christopher,

    Can you pls explain what are the activities performed by the office.workflow.featue..(like uploading the form to central admin templates?…)
    and for any infopath form change should it be deployed only through workflow? since in central admin for the infopath form – workflow enabled -yes/no is a read only property.
    what do we mean exactly by saying publish it to the network location?

    • Hello meena,

      I’m not 100% sure of what is doing the receiver, what I know is that it deploy the infopath to the Central administration and set the workflow enable to YES. That why I think you need to update your form doing an update or you form in your feature (and the solution update copy the form to the CA)

      I don’t understand your question about publishing. It does what It says, it publish your form to a location.

  10. Userino says:

    which is better custom aspx forms or infopath forms in visual studio workflow?

  11. coder says:

    Hi, Christopher!

    Don’t u know how to create custom task forms (not infopath forms) in VS workflow? Didn’t find anything that is clearly explained that.

    • Hello,
      You can create custom aspx and assign them to your task content type (it’s one way)

      in this sample, I associated an aspx page to the first content type on my task list.

      SPList listeTaches = web.GetList(SPUrlUtility.CombineUrl(web.Url, “/Lists/Tches”));

      SPContentType ct = listeTaches.ContentTypes[0];
      ct.EditFormUrl = “_layouts/MyProject/taskeditform.aspx”;
      ct.NewFormUrl = “_layouts/MyProject/taskeditform.aspx”;
      ct.DisplayFormUrl = “_layouts/MyProject/taskeditform.aspx”;
      ct.Update();
      listeTaches.Update();

  12. Basel Badr says:

    Thank you Christopher for the very well written steps of publishing Infopath forms by visual studio project using module and how to register it inside the workflow definition file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s