Workflows in Change Management

SharePoint webhooks provide a powerful means to automate tasks in a change order process by enabling real-time notifications whenever items in a SharePoint list are created, updated, or deleted. For instance, in a typical change management process, these webhooks can be utilized to trigger workflows that automatically update task statuses, notify approvers or stakeholders via email, synchronize data across systems, or archive completed change orders. These automated tasks help streamline the various stages of change management, such as request initiation, impact assessment, review and approval, implementation, and finally, closure and documentation, thereby enhancing efficiency and reducing manual overhead in managing changes within an organization.

To set up a SharePoint webhook using an Azure Function that sends an email to an approver in a change order process, you need to follow several steps. These involve setting up the SharePoint environment, creating an Azure Function, and writing the code to handle webhook events and send the email. Here’s a step-by-step guide:

Step 1: Prepare the SharePoint Site

  1. Enable Webhooks: Ensure that your SharePoint Online environment supports webhooks. Most modern SharePoint setups do.
  2. Identify the List: Confirm the name of the list (“change orders”) and ensure the field storing the approver’s information (“Approver”) is properly configured to hold SharePoint User type data.

Step 2: Register the Webhook

  1. Create an Azure AD App: Register an application in Azure AD to authenticate your webhook. This app will give you an App ID and App Secret which are needed to create the webhook.
  2. Get Permissions: Assign the necessary permissions (like Sites.ReadWrite.All) to your app in Azure AD so it can read and write to SharePoint lists.
  3. Get SharePoint Access Token: You’ll need to implement a method in your Azure Function to obtain an access token using the Azure AD app credentials.
  4. Register Webhook: Using the SharePoint REST API, register the webhook. This involves sending a POST request to the SharePoint list webhook endpoint (https://<site-url>/_api/web/lists/getbytitle('change orders')/subscriptions). The request body should include the notificationUrl (your Azure Function URL), expirationDateTime, and clientState.

Step 3: Create an Azure Function

  1. Setup Azure Function: Create a new Azure Function App in the Azure portal. Choose a runtime that supports your preferred programming language (e.g., C# or JavaScript).
  2. Write the Function Code: Implement the function to handle POST requests. This function will be triggered by SharePoint when changes occur in the “change orders” list.
  3. Parse Webhook Payload: Extract the relevant data from the webhook payload, such as the list item ID and the type of change.

Step 4: Retrieve Approver Details and Send Email

  1. Query SharePoint List: Using the SharePoint REST API, retrieve the details of the changed item, specifically the “Approver” field which contains the user data.
  2. Extract Email Address: From the user data in the “Approver” field, extract the email address.
  3. Send an Email: Implement email sending functionality within the Azure Function. You can use services like SendGrid, Office 365 email, or any SMTP server to send the email to the extracted approver’s email address. Configure this with appropriate API keys and permissions.

Step 5: Testing and Debugging

  1. Test the Function Locally: Use tools like Postman or a similar API testing tool to simulate SharePoint webhook calls to your Azure Function.
  2. Deploy and Monitor: Once tested, deploy your Azure Function. Monitor its performance and logs for any potential errors or adjustments needed.

Step 6: Maintain and Update

  • Regularly check the function for any changes needed due to updates in SharePoint, Azure, or the email service.
  • Ensure that the webhook expiration is updated before it lapses, as SharePoint webhooks expire and need renewal.

This setup will allow you to automatically notify approvers via email when a change order is updated in SharePoint, leveraging Azure Functions for processing and handling the webhook events.

Get Help

Contact us to get help with setting up workflows using Azure or other cloud services.