In this article you will learn about Remote Event Receivers and applicable business cases around the Remote Event Handlers.
In this fourth article in the series on Remote Event Receivers, we will look into some of the applicable business cases around the Remote Event Handlers. You can reach the previous three articles in this series through the following links:
We will investigate the working of the following scenarios which are quite obvious while working with SharePoint List & List Items. Scenario 1: How to restrict users to delete a certain item In order to show case this scenario let’s consider an Item “Product-001-1” added to the List called “Products” as shown below: Now let’s try to delete this item as highlighted below- As soon as the user tries to delete the item SharePoint looks for any registered Event Receiver with the List and looks for its Receiver Definition to see what events this Receiver is allowed to receive and executes it. In our case we have registered the following Receiver Definition with the list- Let’s investigate the code for registering Remote Event Handler – Since this is a Before Event (as explained in one of the earlier post “SharePoint 2013: Remote Event Receivers”), we need to write the Code in “ProcessEvent” Method.
Scenario 2: How to get Item Details after Item has been updated In order to showcase this scenario we can consider the same item as above and this time let’s Edit the item as highlighted below: Now the next thing is to investigate the code for registered Remote Event Handler. Since this is an After Event (as explained in one of the earlier post “SharePoint 2013: Remote Event Receivers”), we need to write the Code in “ProcessOneWayEvent” Method.
Scenario 3: How to validate User inputs using Remote Event Receivers This scenario will talk about validating user inputs and terminate the execution as soon as the input value falls outside the valid value range. For instance in this demo we are assuming a hypothetical business requirement demanding “Item Price should not exceed $300”. In order to showcase this validation scenario we can consider the same Item as mentioned above. Let’s edit the item as shown below Now specify the Item Price any greater than $300, here we are updating the Product Price as $350. As soon as we try to save the item, SharePoint hans over the control to Remote Event Receiver which is registered with this list on Item Updating Event and Event Receiver validates the Item Price value against the specified business logic which on fail produces the error message “Price cannot exceed $300” as highlighted below- If we look into the logic driving this business requirement we can see:
These few simple scenarios might help you to understand the mechanics and objects exposed by Remote Event Receiver API that can be extended to achieve even more complex business scenarios.
SharePoint Online And Office 365 Administration