2015-04-17

Ever have someone ask you to build a registration form for training or sign-up sheet for an event on SharePoint?  Seems simple enough until you go to do it…  Well next time that happens give this a try!

Create the Lists

  • Calendar List – use the out of the box Calendar list and add these fields
    • Seats – Number field
    • FilledSeats – Number field
    • RemainingSeats
      • Calculated Field
      • Formula: =Seats-FilledSeats
      • Data type returned: Number
    • SeatsIncrement
      • Calculated Field
      • Formula: =FilledSeats+1
      • Data type returned: Number
    • Closed – Yes/No
      • Default Value: No
    • StaticID – Number
      • Note: This is a Hack we have to put in because we can’t use the real ID field in a calculated column. We will use a workflow to fill it in correctly later. I am open to suggestions on a better way to do this
    • Register
      • Calculated Field
      • Data type returned: Single line of text
      • Formula :
=IF(Closed=TRUE,"Closed for registration",IF(RemainingSeats>0,"<a href='#' onclick='OpenLandLRegistration("&StaticID&")'>Register</a>","Class is Full"))
  • Attendees List – custom SharePoint list, add these fields:
    • Username
    • Single line of Text Field
    • Required
  • Meeting
    • Lookup Field
      • Get Information from – Calendar List created earlier
      • In this column – Title field
    • MeetingID – Single line of text field

Workflows

SetStaticClassID Workflow

The SetStaticClassID Workflow is really a hack because SharePoint won’t let you use the ID field in the calculated columns. All we are doing is setting a number field with the ID field every time the calendar item is created or modified. For our particular situation, this will work fine. However, don’t assume this technique will work in every situation you need to use the ID field in a calculated column.

Go to the Calendar List created earlier. Edit the Calendar List in SharePoint Designer (note: you will need SharePoint Designer 2010 to do this)

  • Choose List Workflow in the Ribbon of SharePoint Designer
  • Give the Workflow a good name – something like SetStaticClassID
  • Add an Action – “Set Field in Current Item”
  • Click the “field” link – choose StaticID
  • Click the “value” link and clickt the fx button:
    • Data source: Current Item
    • Field from source: ID

Your Workflow should look like this:

setstaticid

Save your work.

Go back to the settings page for the Workflow. Set the Start Options for “Start Workflow automatically when an item is created” and “Start workflow automatically when an item is changed”

Save and Publish your workflow.

Registration Workflow

The Registration Workflow is one of the main parts of this solution. This is the Workflow that will update the remaining seats in the calendar list when an Attendee register for the course.

Go to the Attendee List created earlier. Edit the Attendee List in SharePoint Designer.

  • Choose List Workflow in the Ribbon of SharePoint Designer
  • Give the Workflow a good name – something like Registration
  • Add an Action – “Update List Item”
  • Click the “this list” link in the action
  • Change the list ot the Calendar list created earlier
  • Click the “Add…” button
    • Choose “FilledSeats”
    • Click the fx button for the value
      • Data source: Calendar
      • Field from source: SeatIncrement
      • Field: ID
      • Value – click the fx button
        • Data source: Current Item
        • Field from source: Meeting
  • In the Find the list item section
    • Field: ID
    • Value – click the fx button
      • Data source: Current Item
      • Field from source: Meeting

Save your work.

Go back to the settings page for the Workflow. Set the Start Options for “Start Workflow automatically when an item is created”

Save and Publish your workflow. It should look like this :

registration

InfoPath Form

The end user will eventually register through the InfoPath form on the Attendees list.

  • Go to the Attendees list in SharePoint
  • Choose to Customize the Form in the Ribbon (note: you will need InfoPath Designer to do this)
  • AutoPopulate the Title Field: In the title field of the form
    • Right-click – Text Box Properties
    • Default value – click the fx button
    • Add this in for the Formula:
    • concat(userName(), " registration for event number ", Meeting)

Note: copy and paste will not work on this formula. You will have to delete the “Meeting” string in the formula and use the “Insert Field or Group” button instead and choose the Meeting field

  • Add a formatting rule – “Hide this control” to both the Title and MeetingID fieldsNote: You should also delete the label for these fields and move them to the bottom of the form and delete the empty table rows they were in. This will make these fields invisible to the end user, but they will still be there to bind to the SharePoint list
  • In the Username field of the form
    • Right-click – Text Box Properties
    • Default value – click the fx button
    • Add this in for the Formula: userName()
  • Add a formatting rule to the Username field to “Disable this control”
  • In the Meeting field of the form
    • Click the “Default Value” button in the Control Tools – Properties tab of the ribbon
    • Default value – click the fx button
    • Add this in for the Formula using the “Insert Field or Group” button: MeetingID
  • Add a formatting rule to the Meeting field to “Disable this control”
  • Publish the form

Querystring

In order to automatically set the the meeting in the InfoPath form, we will use a query string to the MeetingID field. There are a few problems to this:

  1. You can’t send querystrings to InfoPath: Solution = use a Query String Filter Web Part on the SharePoint page
  1. The Query String Filter Web Part can’t set a lookup field. Since our Meeting column is a lookup field, this won’t work. Thus, we created a MeetingID field. This is a hidden field on the InfoPath form that is purely used to set the Meeting lookup field in the form. The end user will never see this field

Go to the Attendees list on the SharePoint site.

Right-Click on the “Add new item” link and choose to open in a new window or a new tab.

Now you will be on the edit form page – click Site Actions – Edit Page.

Add a Query String (URL) Filter field to the site.

Modify the Settings and add

  • Fiter Name – QueryString
  • Query String Parameter Name – meeting_id
Connect the Query String (URL) Filter Web Part to the InfoPath Form Web Part

Use the “MeetingID” filed as the Consumer Field Name

Now when anyone comes to the new form of your Attendees list, it will be filtered by the querystring on the MeetingID field. The InfoPath form is setup to use the MeetingID text field to populate the Meeting dropdown box. This allows us to automatically pick the dropdown of the event the attendee wishes to register from.

Javascript

The last step to this is a javascript file. The javascript does two things:

  • Creates the dialog box javascript to open our new form. The call to this javascript method is in the calculated field on the attendees list to register
  • Turns the calculated field column into html
Note: The solution below uses JQuery because it is the easiest way to loop through multiple elements on the client side. If you do not have JQuery in your solution then:
 
  • Download the latest version of JQuery
  • Upload the file to your SharePoint site. I usually like to use the Style Library library at the root of the site collection
  • Add a reference to JQuery on your page:
<script type="text/javascript" src="/Style Library/jquery-1.7.2.min.js"></script>

Note: consider adding this as the first line of text in a Text File and then add the rest of the Javascript below to that same Text File. Then you can upload the Text File to a library on your site (I usually use the Style Library or Site Assets Library for this) and you can reference the text file from a Content Editor WebPart on the page we are creating.

IMPORTANT: Please change the url in the javascript to point to your new form (remember, you can right click on the add new on the Attendees list and open in new tab or window). This will show you the path to the new form and the List GUID. Also, make sure you keep the meeting_id at the end as a query string parameter.

<script type="text/javascript">

function OpenLandLRegistration(meeting_id)
{
	var options = {
	url:"/Lists/Attendees/Item/newifs.aspx?List=034d3042%2D1f03%2D43cc%2D96fc%2Dc4ef0acfa92a&meeting_id=" + meeting_id,
	width: 750,
	height: 600, 
	dialogReturnValueCallback: DialogCallback
	};
 
	SP.UI.ModalDialog.showModalDialog(options);

}

function DialogCallback(dialogResult, returnValue)
{ }

// Reformat the url in the calculated column

reformatCalculatedColumnUrl();

function reformatCalculatedColumnUrl()
{
	$(".ms-listviewtable td.ms-vb2:contains('href')").each(function(){
 	$(this).html($(this).text());
	}); 
}
</script>

Putting it all together

SharePoint, put a Content Editor WebPart on your page and reference the text file in the options of the Content Editor Web Part. Just make sure this Content Editor WebPart is underneath the Calendar list webpart)

Edit the Calendar list webpart and choose the default view (this should be the All Events or Current Events view depending on yoru requirements). Do not use the Default Calendar view (so that you can show the new register link). Modify the view you chose. Make sure the “Register” column is visible to the end users because that is the link they will click to register.

Now the end users can add a new meeting in the Calendar (make sure they know to set the amount of seats available). I also suggest putting a nice message on the InfoPath form telling the end user to Save the form to register for the class. Otherwise, it might not be intuitive for the end user to know to hit the Save button in order to register. You could also add a Register button that just saves the form if you want.

About the author 

Rick Mucha