0

I have being developing server-side event receivers for many years and for many projects. Now I want to start my first experience in developing remote event receivers inside my SP 2013 on-premises. so I create the following using VS 2015 Professional:- 1. Create a new SP add-in. of type SharePoint hosted 2. Add a new event receiver which gets fired when item is being adding for “Issue Tracking” list. Now I am facing some difficulties in understanding if these properties are available inside remote event receivers as in the server side event receiver:-

  1. Can I define the scope for my remote event receiver to be “Web” or “Site”?
  2. Most of the tutorials I read about which talks about remote event receivers will create a new list as part of the SharePoint add-in. so can I create a new remote event receiver which will get fired on existing lists?
  3. I am not sure how I can publish my remote event receiver to my app catalogue. Now I right click on the remote event receiver inside VS 2015.then I select “New” for the current profile. But when I click on “Create new Profile” the dialog will automatically get closed.

enter image description here

So I am not sure how I can publish my remote ER to my app catalogue site ?? so can anyone adivce on the above 3 points please?

1

The documentation around Remote Event Receivers is really unfortunate. There's an opportunity for someone to write a blog post to clarify how it works in practice.

There are two components to a Remote Event Receiver:

  • The web service itself
  • The registration of the remote event receiver.

Note that neither of those components contains the word "App". In fact, the entire App/Add-in concept is completely unnecessary for the creation of Remote Event Receivers. The Visual Studio tooling for RERs does so in an App context, so that's what most people go with.

Just deploy your app web project as written to an Azure web site. That will handle the first component. Forget all about the app part, unless you need it to be an App for some reason.

Next, you need to register your RER with the target site. There is a neat PnP Cmdlet that does this in a one-liner:

Add-PnPEventReceiver -List "ProjectList" -Name "TestEventReceiver" -Url https://yourserver.azurewebsites.net/eventreceiver.svc -EventReceiverType ItemAdded -Synchronization Asynchronous

https://msdn.microsoft.com/en-us/pnp_powershell/addpnpeventreceiver

Or, you could do it in C# CSOM:

EventReceiverDefinitionCreationInformation receiver = new 

EventReceiverDefinitionCreationInformation();
  receiver.EventType = EventReceiverType.ItemUpdated;
  receiver.ReceiverUrl = "https://yourserver.azurewebsites.net/eventreceiver.svc";
  receiver.ReceiverName = "My RER";
  receiver.Synchronization = EventReceiverSynchronization.Asynchronous;

  myList.EventReceivers.Add(receiver);
  clientContext.ExecuteQuery();

If you need to automate this you'll need to provide a mechanism for that. I typically will wrap this into a site provisioning solution (C#) or if it needs to be applied in a one-off solution, I'll use the PowerShell.

By the way, Remote Event Receivers do not have the concept of Scope. You can think of them all as web-scoped.

edit: I've written a "starter project" that I use for remote event receivers that only includes the necessary stuff and omits all the app nonsense included with the VS template. Feel free to clone it and use it. https://github.com/dgusoff/RemoteEventReceiver.Starter

  • thanks a lot for your reply. so now let say i create the remote event receiver using VS tooling or your "starter project".. then why do i need to deploy it inside Azure web site (which currently i do not have ) as i am working on sharepoint 2013 on-premise,,, so can I deploy the remote event receiver to my app catalog site.. and then install the remote event receiver inside my related site/s by going to "site content">>"add app">>"from your organization">>select the remote event receiver which i created ?? – john Gu Jun 20 '17 at 19:40
  • second question,, can i attach remote event receivers to existing lists?? or the list i want the remote event receiver to work on should be part of the VS project?as most of the tutorials i read will first add a list inside the sharepoint add-in project then they will add the remote event receiver and chose to attach it to the list?? or this is done for demonstration purposes only. and i can attach remote ER to existing lists and libraries as i do with the server-side ER? – john Gu Jun 20 '17 at 19:41
  • 1
    Yep, you can attach to pre-existing lists using the code samples I provided. – Derek Gusoff Jun 20 '17 at 19:50
  • 1
    If you want to deploy an app to your app catalog, then the attachment code would live in the app installed event. – Derek Gusoff Jun 20 '17 at 19:54
  • 1
    This is exactly the problem with using the VS App tooling. It doesn't map well to real world situations. The code I shared attaches the RER to a single specific list. – Derek Gusoff Jun 21 '17 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.