Webhook Success Key #4: Carefully Manage SharePoint State
John E. Huschka, January 25, 2018
Azure Functions — Internet cloud based custom code for SharePoint and Office 365.
SharePoint Webhooks — Connections that allow us to attach custom code to SharePoint that is called when events occur.
This post is part of our blog series and demonstration code on achieving webhook success.
We frequently see two major uses of event driven processing in SharePoint:
Data Synchronization: Essentially, when you need to perform calculations on your data and/or move/copy data from one place to another.
Process Automation (workflow): When new data or changes in existing data require action to further a business process—providing information to a person or automated system, for example.
If your webhook is doing data synchronization, it probably has no state considerations. For example, if your webhook needs to concatenate names to create a full name, there is no state management.
Here, if the webhook fires every time there is a change, it will simply re-update the full name.
State management is critical however, if you are doing SharePoint business process automation, such as payment processing.
As an example, let’s assume that we have a SharePoint list for which a webhook makes payments. A new item (“second item”) is entered into the list:
The webhook runs, making a payment and updating the item’s Payment Status and Webhook Processed date:
It is critical that the payment not be re-sent, no matter how many times the webhook is fired. Therefore, the QueueTransactionProcessor checks the Webhook Processed date when it runs on subsequent webhook calls to avoid making a re-payment. The QueueTransactionProcessor is using the Webhook Processed date to maintain the state of the payment.
Note that when the webhook handler updates Payment Status and Webhook Processed date columns, the webhook will re-fire. Aside from the extra processing caused by the re-fire, this should cause no issues as long as state is being properly maintained and checked by the webhook handler.
More in our "Webhook Success Keys" series:
We at Collaboration Foundry are experts in SharePoint and Office 365. If you need assistance, we can help.
Contact us.
Also, don't forget to take a look at our
blog for more helpful tips and techniques.