You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Event receivers and list event receivers in the SharePoint Add-in model
3
-
ms.date: 04/22/2020
3
+
description: In an SharePoint Add-in model scenario, event receivers are created outside of SharePoint inside a web service and registered with SharePoint. These are called as Remote Event Receivers (RER). In this scenario, the event receiver code runs on the web server where the web service is hosted.
4
+
ms.date: 01/29/2021
4
5
localization_priority: Priority
5
6
---
6
-
Event receivers and list event receivers in the SharePoint Add-in model
# Event receivers and list event receivers in the SharePoint Add-in model
8
8
9
-
## Summary
9
+
The approach you take to handle events in SharePoint is different in the new SharePoint Add-in model than it was with Full Trust Code.
10
+
11
+
In a typical Full Trust Code (FTC) / Farm Solution scenario, Event Receivers and List Event Receivers were created with the SharePoint
10
12
11
-
The approach you take to handle events in SharePoint is different in the new SharePoint Add-in model than it was with Full Trust Code.
12
-
In a typical Full Trust Code (FTC) / Farm Solution scenario, Event Receivers and List Event Receivers were created with the SharePoint
13
13
Server Side Object Model code and deployed via Solutions. In this scenario, the event receiver code runs on the SharePoint server.
14
14
15
-
In an SharePoint Add-in model scenario, event receivers are created outside of SharePoint inside a web service and registered with SharePoint.
16
-
These are called as *Remote Event Receivers (RER)*. In this scenario, the event receiver code runs on the web server where the web service is hosted.
15
+
In an SharePoint Add-in model scenario, event receivers are created outside of SharePoint inside a web service and registered with SharePoint. These are called as *Remote Event Receivers (RER)*. In this scenario, the event receiver code runs on the web server where the web service is hosted.
17
16
18
-
>**Important**
19
-
>As of January 2017 SharePoint Online does support list webhooks which you can use instead of "-ed" remote event receivers. Checkout[Overview of SharePoint webhooks](https://developer.microsoft.com/office/sharepoint/docs/apis/webhooks/overview-sharepoint-webhooks) to learn more about webhooks. Also note that several webhook samples are available from the [sp-dev-samples](https://github.com/SharePoint/sp-dev-samples/tree/master/Samples) GitHub repository.
17
+
>[!IMPORTANT]
18
+
>As of January 2017 SharePoint Online does support list webhooks which you can use instead of "-ed" remote event receivers. See[Overview of SharePoint webhooks](../apis/webhooks/overview-sharepoint-webhooks.md) to learn more about webhooks. Also note that several webhook samples are available from the [sp-dev-samples](https://github.com/SharePoint/sp-dev-samples/tree/master/Samples) GitHub repository.
20
19
21
20
## High-level guidelines
22
21
@@ -29,44 +28,45 @@ As a rule of a thumb, we would like to provide the following high-level guidelin
29
28
- Normal events like ItemAdded have also timeout of 30 seconds, but there's no retry mechanism
30
29
- Event receivers added to host web without app context, for example with SharePointOnlineCredentials or other means, will not return access token and you'll have to access the host web with app-only access token
31
30
- Adding event receivers to the host web is supported.
32
-
+ It is only possible to do this via CSOM/REST APIs, not by using Visual Studio wizards.
31
+
- It is only possible to do this via CSOM/REST APIs, not by using Visual Studio wizards.
33
32
- SharePoint will absolutely call the event receiver end points configured for a given event. However, there is no guarantee that the code in the event receiver end points will execute because the code is not running on the SharePoint server.
34
-
35
-
For example:
36
-
37
-
If the event receiver end point URL is unavailable the event receiver code will not execute. The URL might be unavailable due to several reasons. Some of the most common reasons include a misconfiguration when the end point URL is registered, DNS issues when trying to resolve the URL, or the website hosting the end point is shut down or in an inoperable state.
38
33
39
-
Additionally, if there is a bug in poorly written event receiver code there is no way to notify SharePoint the bug occurred and the event should be executed again. You can work around this to some degree with event receivers attached to SharePoint lists. See below for more information about this approach.
34
+
For example:
35
+
36
+
If the event receiver end point URL is unavailable the event receiver code will not execute. The URL might be unavailable due to several reasons. Some of the most common reasons include a misconfiguration when the end point URL is registered, DNS issues when trying to resolve the URL, or the website hosting the end point is shut down or in an inoperable state.
37
+
38
+
Additionally, if there is a bug in poorly written event receiver code there is no way to notify SharePoint the bug occurred and the event should be executed again. You can work around this to some degree with event receivers attached to SharePoint lists. See below for more information about this approach.
39
+
40
40
- When an event receiver executes a significant amount of code an asynchronous pattern should be used.
41
-
+ See the following MSDN blog post for more information about this pattern. [Using Azure storage queues and WebJobs for async actions in Office 365 (MSDN Blog Post)](https://blogs.msdn.com/b/vesku/archive/2015/03/02/using-azure-storage-queues-and-webjobs-for-async-actions-in-office-365.aspx)
42
-
+ See the following MSDN article for more information about timeouts in event receivers. (Search for timeout in the article.) [Handle events in add-ins for SharePoint (MSDN Article)](https://msdn.microsoft.com/library/office/jj220048.aspx)
41
+
- See the following MSDN blog post for more information about this pattern. [Using Azure storage queues and WebJobs for async actions in Office 365 (MSDN Blog Post)](https://blogs.msdn.com/b/vesku/archive/2015/03/02/using-azure-storage-queues-and-webjobs-for-async-actions-in-office-365.aspx)
42
+
- See the following MSDN article for more information about timeouts in event receivers. (Search for timeout in the article.) [Handle events in add-ins for SharePoint (MSDN Article)](https://msdn.microsoft.com/library/office/jj220048.aspx)
43
43
- When event receivers operate on SharePoint lists we recommend using a specific change tracking mechanism along with the event receiver to ensure higher quality processing.
44
-
+ See the following O365 PnP Code Sample for more information about this pattern and how to implement it. [Core.ListItemChangeMonitor (O365 PnP Sample)](https://github.com/SharePoint/PnP/tree/master/Samples/Core.ListItemChangeMonitor)
44
+
- See the following O365 PnP Code Sample for more information about this pattern and how to implement it. [Core.ListItemChangeMonitor (O365 PnP Sample)](https://github.com/SharePoint/PnP/tree/master/Samples/Core.ListItemChangeMonitor)
45
+
46
+
## Debugging Event Receivers
45
47
48
+
To debug event receivers you need to configure a few different things in Azure and Visual Studio. The following article provide step by step instructions and more information related to debugging.
46
49
47
-
Debugging Event Receivers
48
-
-------------------------
49
-
To debug event receivers you need to configure a few different things in Azure and Visual Studio. The following article provide step by step instructions and more information related to debugging.
50
-
-[Debug and troubleshoot a remote event receiver in an add-in for SharePoint MSDN Blog Post)](https://msdn.microsoft.com/library/office/dn275975.aspx)
50
+
-[Debug and troubleshoot a remote event receiver in an add-in for SharePoint MSDN Blog Post)](https://msdn.microsoft.com/library/office/dn275975.aspx)
+ This sample hows how a SharePoint Add-in can use the App Installed event to perform additional work in the host web, such as attaching event receivers to lists in the host web.
57
-
+ See the following MSDN blog post for more information about this pattern. [Attaching Remote Event Receivers to Lists in the Host Web (MSDN Blog Post)](https://blogs.msdn.com/b/kaevans/archive/2014/02/26/attaching-remote-event-receivers-to-lists-in-the-host-web.aspx)
55
+
- This sample hows how a SharePoint Add-in can use the App Installed event to perform additional work in the host web, such as attaching event receivers to lists in the host web.
56
+
- See the following MSDN blog post for more information about this pattern. [Attaching Remote Event Receivers to Lists in the Host Web (MSDN Blog Post)](https://blogs.msdn.com/b/kaevans/archive/2014/02/26/attaching-remote-event-receivers-to-lists-in-the-host-web.aspx)
+ This sample shows how to implement handlers for the AppInstalled and AppUninstalling events that:
60
-
1. Incorporate rollback logic if the handler encounters an error.
61
-
2. Incorporate "already done" logic to accommodate the fact that SharePoint retries the handler up to three more times if it fails or takes more than 30 seconds to complete.
62
-
3. Use the handler delegation strategy to minimize calls from the handler web service to SharePoint.
63
-
4. Use the CSOM classes ExceptionHandlingScope and ConditionalScope.
58
+
- This sample shows how to implement handlers for the AppInstalled and AppUninstalling events that:
59
+
1. Incorporate rollback logic if the handler encounters an error.
60
+
1. Incorporate "already done" logic to accommodate the fact that SharePoint retries the handler up to three more times if it fails or takes more than 30 seconds to complete.
61
+
1. Use the handler delegation strategy to minimize calls from the handler web service to SharePoint.
62
+
1. Use the CSOM classes ExceptionHandlingScope and ConditionalScope.
+ This sample shows how to implement handlers for the AppInstalled and AppUninstalling events that:
66
-
1. Incorporate rollback logic if the handler encounters an error.
67
-
2. Incorporate "already done" logic to accommodate the fact that SharePoint retries the handler up to three more times if it fails or takes more than 30 seconds to complete.
64
+
- This sample shows how to implement handlers for the AppInstalled and AppUninstalling events that:
65
+
1. Incorporate rollback logic if the handler encounters an error.
66
+
1. Incorporate "already done" logic to accommodate the fact that SharePoint retries the handler up to three more times if it fails or takes more than 30 seconds to complete.
68
67
69
68
## Related links
69
+
70
70
-[Remote event receivers in SharePoint 2013 FAQ (MSDN Article)](https://msdn.microsoft.com/library/office/dn456315.aspx)
71
71
-[Create a remote event receiver in add-ins for SharePoint (MSDN Article)](https://msdn.microsoft.com/library/office/jj220043.aspx)
72
72
-[Create an app event receiver in SharePoint 2013 (MSDN Article)](https://msdn.microsoft.com/library/office/jj220052.aspx)
0 commit comments