Webhook Success Key #3: Focus on SharePoint Changes That You Need

John E. Huschka, January 25, 2018

Target Audience:

SharePoint Developer

Technology:

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.

SharePoint tracks many changes on many objects. To avoid having to download and process unneeded change information, it is important that you query SharePoint for only the change information that you need.

The ChangeQuery class provides you with twenty-eight properties by which you can control the changes that SharePoint returns.

The first step in setting these properties is proper use of the ChangeQuery constructor, which provides two parameters:

public ChangeQuery(
    bool allChangeObjectTypes,
    bool allChangeTypes
)

These two parameters are defined as follows:

  • allChangeObjectTypes: Provides the default value for ChangeQuery properties that control the object types for which changes are returned. Supplying true means that these properties will have a value of true. Meaning: Changes for all object types will be returned.
  • allChangeTypes: Provides the default value for ChangeQuery properties that control which change types are returned. Supplying true means that these properties will have a value of true. Meaning: All types of changes will be returned.

The table below shows each of ChangeQuery's twenty-eight properties along with the constructor parameter that provides its default value. Note that there is a parameter-less constructor for ChangeQuery that is equivalent to providing both parameters as false.

ChangeQuery Property Definition Default from Constructor Parameter
Add Specifies whether add changes are included. allChangeTypes
Alert Specifies whether changes to alerts are included. allChangeObjectTypes
ContentType Specifies whether changes to content types are included. allChangeObjectTypes
DeleteObject Specifies whether delete changes are included. allChangeTypes
Field Specifies whether changes to site columns are included. allChangeObjectTypes
File Specifies whether changes to files are included. allChangeObjectTypes
Folder Specifies whether changes to folders are included. allChangeObjectTypes
Group Specifies whether changes to groups are included. allChangeObjectTypes
GroupMembershipAdd Specifies whether adding users to groups is included. allChangeTypes
GroupMembershipDelete Specifies whether deleting users from the groups is included. allChangeTypes
Item Specifies whether general changes to list items are included. allChangeObjectTypes
List Specifies whether changes to lists are included. allChangeObjectTypes
Move Specifies whether move changes are included. allChangeTypes
Navigation Specifies whether changes to the navigation structure of a site collection are included. allChangeTypes
Rename Specifies whether renaming changes are included. allChangeTypes
Restore Specifies whether restoring items from the recycle bin or from backups is included. allChangeTypes
RoleAssignmentAdd Specifies whether adding role assignments is included. allChangeTypes
RoleAssignmentDelete Specifies whether deleting role assignments is included. allChangeTypes
RoleDefinitionAdd Specifies whether adding role definitions is included. allChangeTypes
RoleDefinitionDelete Specifies whether deleting role definitions is included. allChangeTypes
RoleDefinitionUpdate Specifies whether modifying role definitions is included. allChangeTypes
SecurityPolicy Specifies whether modifications to security policies are included. allChangeObjectTypes
Site Specifies whether changes to site collections are included. allChangeObjectTypes
SystemUpdate Specifies whether updates made using the item SystemUpdate method are included. allChangeTypes
Update Specifies whether update changes are included. allChangeTypes
User Specifies whether changes to users are included. allChangeObjectTypes
View Specifies whether changes to views are included. allChangeObjectTypes
Web Specifies whether changes to Web sites are included. allChangeObjectTypes

So, when you are querying SharePoint, set these properties to limit the returned changes to the minimum set required. We recommend calling the constructor with both parameters false and then setting individual properties appropriately for the changes that you need, which is what our QueueTransactionProcessor does:

The ChangeQuery class provides you with many options for limiting your query for SharePoint changes. Proper use will save you much processing logic and time.