Home > MOSS 2007, SharePoint, SharePoint 2010, SharePoint 2013 > SharePoint Survey List – EventReceiver

SharePoint Survey List – EventReceiver

SharePoint Survey list behaves differently compared to others. A survey can have many questions, that can be on different pages. There must be scenarios where we need to do calculations once a Survey response is completed. For doing this the best option is event receiver customization. In this case we need to handle both ItemAdded and ItemUpdated events.

When a user respond’s to a survey the value in field Completed will be 255. Once the user clicks on the finish button the value changes to 1. Hence in the receiver we need to take action only once the value equals 1.

Below is a template you can use

using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace Survey
{    
    /// <summary>
    /// List Item Events
    /// </summary>
    public class SurveyListReceiver : SPItemEventReceiver
    {
       /// <summary>
       /// An item was added.
       /// </summary>
       public override void ItemAdded(SPItemEventProperties properties)
       {
           try
           {
               if (properties.ListItem["Completed"] != null && properties.ListItem["Completed"].ToString() == "1")
               {
                   //Survey is complete. Do The Action
               }
           }
           catch
           {
           }
           base.ItemAdded(properties);
       }

       /// <summary>
       /// An item was updated.
       /// </summary>
       public override void ItemUpdated(SPItemEventProperties properties)
       {
           try
           {
               if (properties.ListItem["Completed"] != null && properties.ListItem["Completed"].ToString() == "1")
               {
                   //Survey is complete. Do The Action
               }
           }
           catch
           {
           }
           base.ItemUpdated(properties);
       }
    }
}
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: