Easy WSS Forms with Workflow and Anonymous Access

I am just having loads of fun with the anonymous membership provider. I mentioned in a previous post that the provider approach solves a wider range of issues than merely allowing anonymous types to upload files to a document library.

For example, you can’t create a workflow that is invoked by an anonymous user in WSS. Here is a thread on the MSDN forums about the issue. The solution the developer came up with was to muck about with the list forms on the list in question, just as I was contemplating before Søren Nielsen bought me a ticket on the clue train with his suggestion of a custom provider.

As I announced a few days ago, we are now signing up folks for the SharePoint developer core skills classes in November and December. I thought it would be nice to create a form to allow folks to request more information. Now that I have the ability to do work flows without authentication, I thought it would be fun to create the form using plain old WSS workflow via SharePoint Designer instead of creating a web part or user control. As it turns out, this is a lot easier than creating, deploying, and building a web part page using a control.

You can see the result here. If you fill out the form and hit ‘Submit Request’ I will get an email.

It’s worth noting that this technique works well for creating a form quickly even when the anonymous scenario does not exist. If you need a quick and easy data entry form for WSS, follow the steps below and ignore the bits about Anon. Just make sure your users have permissions to contribute to the list that starts the work flow and if the work flow adds items to any other lists then those as well!!!

How it’s done

The first thing you need to do is add Anon to the site’s Visitors group. WSS workflow is, to put it charitably, picky about permissions. Even though I had given Anon specific access to the list where the workflow was attached, it didn’t work until I added Anon to the site. It occurs to me I probably should have done that anyway. And so, even though, it was one of the last things I did, just save yourself some trouble if you set the provider up previously and do that now if you haven’t already.

Anyway…

Workflow in WSS is designed to work against list items. A workflow can be started manually, when an item is created, or when an item changes. Whichever way, if you want a workflow you need a list item and to have a list item, of course, you need a list. Therefore step one in this exercise is to create a custom list and add an item.

  • Create a new custom list

  • Add an item to the list

  • Give Anon ‘Contribute’ permissions to the list


  • Open the site in SharePoint Designer
  • Form the File menu, choose New | Workflow
  • The Workflow Designer will open. Fill the form out as follows:
  • Click the Initiation button. This is where we will define the fields for our form.
  • Add the following fields:

Your Name

Single line of text

 

Company

Single line of text

 

eMail

Single line of text

 

Phone

Single line of text

 

Contact Preference

Choice (menu to choose from)

Class

Choice (menu to choose from)

The parameters form should now look like this:

Click OK

  • Click Next on the Workflow Designer and then click Actions and choose "Send an email" to add an action. Because we want this workflow to happen every time we will not create any conditions.
  • Click the this message link and fill out the email form as follows except using your own email address!:
  • Add fields from the form the user filled out by clicking Add Lookup to Body. Choose ‘Workflow Data’ from the Source dropdown to populate the Field with the fields from step 8.

    Create an email body that has all of the information and wind up with something like this:

    and click OK.

  • Finally click Finish in the Workflow Designer to deploy the new workflow.
  • At this point you may want to tidy up the workflow form a bit. In my case I wanted to change the text on the buttons and do some styling. You can find it in the folder list in SharePoint Designer and edit it as you would any form. However, you will want to back up any edits you make because if you edit the workflow SPD will regenerate the form and stomp your changes!
  • Great! So now we have all the pieces we need. To finish it up we need to create a link to our new form and put it somewhere. We can’t simply link to the form itself however because the workflow requires a list item to attach itself to. To get the link, navigate to the list created in step 1 and choose Workflows from the item dropdown.

  • Right click the Request Workflow link and choose Properties
  • Copy the address, in this case, /Workflows/Request%20Workflow/Request%20Workflow.aspx?List=ea10f5a1-5401-4c96-bcbf-d91db261dd76&ID=1&TemplateID={d4d1f324-bfcf-44f6-8f10-efdd31400650}&Source=http%3A%2F%2Finternal%2Eskinner%2Edemo%2FLists%2FWorkflow%2520List%2FAllItems%2Easpx. That is the url you will use to access the form and it will always work unless you delete the item! I recommend hiding the list to keep anyone from doing it accidentally. If someone is savvy enough and wants to be a jerk they still can get to the item by parsing out the link. So, this does have the disadvantage of not being as robust as a handmade control, but it is way easier. This is one case where SharePoints seemingly arbitrary need to force certain levels of permissions actually make it less secure in my opinion.
  • Test your form by clicking the link and filling it out. If you did everything right you will get an email with all the nice email with all of the information, but you also wound up redirected to that list and that is no good at all! So there is one last thing we need to do to make this solution complete!
  • We can’t fix the redirect on the workflow form because it is actually taking place on the server and we have no way to change it. So instead we have to use some simple java script to do the redirect on the client side.
    Return to SharePoint Designer and edit the AllItems.aspx form for the list.
  • Find the PlaceHolderAdditionalPageHead place holder and change it to include the script.
    <asp:content contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">

        <SharePoint:RssLink runat="server"/>

        <script>

        alert(‘Thank you for your interest. We will contact you shortly.’);

        window.location = ‘http://www.someotherUrl/’;

        </script>

    </asp:content>

  • Save your work!
  • Finally, (shew!) hide the list from the browser and from the all items list by right clicking the list and choosing properties.
  • Check Hide from Browsers and hit OK

That’s it! Enjoy!!!

Now get out there and build some forms.

Author: Doug Ware