SharePoint Online (2013) Event Receiver Not Working

Hello,

My name is Brandon. This is my first time working with Visual Studio. I have an Event Receiver I have created within Visual Studio 2012. I have SharePoint 2013 configured locally on my laptop. The Event Receiver Solution I have created for SharePoint 2013 works. When I upload the .WSP to SharePoint Online (2013) the Event Receiver does nothing. The feature is activated within Solutions and under Manage Site Features for the sub site this is to run on. Here is the information if anyone could assist. I am hoping this has not been depreciated by Microsoft yet as everywhere I have read online says that if it is working locally it should work for SharePoint Online.

Event Receiver Purpose: The Event Receiver is to run when a new Item is added to a custom list. The event receiver looks up the highest value (Number) EX: 5643 within the List for ColumnName = Project and sets the value to + 1.

When creating a new item in the list the value you set itself to highest value + 1. From the example above the number should be 5644.

As stated this works for SharePoint 2013 On Premises, but is not working for SharePoint Online (2013) "The Project Column stays blank rather than generating the next number as it should."

The Coding for the Event Receiver is below the image.

Feature1.xml

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
         Scope="Web">
  <Properties>
    <Property Key="GloballyAvailable" Value="true" />
  </Properties>
</Feature>

Elements.xml

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListUrl="Lists/Sequential%20Numbering%20List">
  <Receiver>
<Name>EventReceiver1ItemAdded</Name>
<Type>ItemAdded</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>EVENTRECEIVER---EDITED TOOK OUT REAL NAME.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>

EventReceiver1.CS

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

namespace EVENTRECEIVER---EDITED TOOK OUT REAL NAME.EventReceiver1
{
    /// <summary>
    /// List Item Events
    /// </summary>
    public class EventReceiver1 : SPItemEventReceiver
    {
        /// <summary>
        /// An item is being added.
        /// </summary>
        private static int GetMaxValue(SPItemEventProperties properties)
        {
            SPWeb web = properties.OpenWeb();
            SPList list = properties.List;
            int highestValue = 0;

            SPQuery query = new SPQuery();
            query.Query = @"<OrderBy>
                             <FieldRef Name='Project' Ascending='FALSE' />
                         </OrderBy><RowLimit>1</RowLimit>";

            SPListItemCollection itemcollection = list.GetItems(query);
            if (itemcollection.Count > 0)
            {
                SPListItem item = itemcollection[0];
                highestValue = Convert.ToInt32(item["Project"]);
            }


            return highestValue;
        }

        /// <summary>
        /// An item is being added
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);

            int highestValue = GetMaxValue(properties) + 1;
            properties.AfterProperties.ChangedProperties.Add("Project", highestValue);
            properties.Status = SPEventReceiverStatus.Continue;
        }

    }
}

August 20th, 2015 3:04am

Hi,

Per my knowledge, SharePoint Online doesn't support farm solution event receiver. 

In SharePoint Online, we need to use Remote Event Receiver instead of event receiver.

Here are some detailed articles for your reference:

Create a remote event receiver in SharePoint Add-ins

Remote event receivers in SharePoint 2013 FAQ

Thanks

Best Regards

Free Windows Admin Tool Kit Click here and download it now
August 20th, 2015 10:52pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics