August 14, 2024

Harnessing SharePoint OOTB Events with PnP Commands for Automated Permission Updates & Efficient Operations

Introduction

In SharePoint Online, automating operations in response to internal events — such as the creation of new site groups or granting permissions — can significantly streamline administrative tasks. This is particularly vital in environments with multiple associated sites where permissions need to be synchronized regularly. Here's how we can use SharePoint's OOTB events to improve operational efficiency and ensure timely updates across sites.

Challenges in Synchronizing Permissions

Consider a typical scenario in a SharePoint environment with one hub site and several associate sites. When a new user is added to a group in the hub site, the same user must be added across all associated sites. 

If we use the Logic App or Power Automate to sync the permission across all these sites it would require daily SharePoint group checks, leading to permissions synchronization delays.

Innovative Solution Using PnP Commands

To address this delay, we leveraged SharePoint PnP (Patterns and Practices) commands to trigger Flows or Azure Functions directly via HTTP when specific OOTB events occur. This method provides immediate event details such as usernames and group names, which can then be used to synchronize user permissions across sites instantly.

Setup and Configuration

We set up event receivers in SharePoint that respond to specific user group changes. Here are the PnP PowerShell commands used to configure these event receivers:

1. When a User is Added:

 Add-PnPEventReceiver -Name "GroupUserAdded" -Url $functionUrlToAddUser -EventReceiverType GroupUserAdded -Synchronization Asynchronous  

2. When a User is Removed:

 Add-PnPEventReceiver -Name "GroupUserDeleted" -Url $functionUrlToRemoveUser -EventReceiverType GroupUserDeleted -Synchronization Asynchronous  

These commands integrate two Azure Functions: the first triggers when a user is added to any SharePoint group on the Hub site, and the second when a user is removed. This setup ensures that any modifications to user groups are immediately reflected across all associated sites without the need for manual intervention.

Benefits and Capabilities

By leveraging OOTB events, we can perform a variety of operations that respond dynamically to changes within the SharePoint environment. These include but are not limited to:

  • Adding, updating, or deleting items, lists, and sites
  • Managing group and role definitions and assignments
  • Handling file movements and attachment operations

Conclusion

Utilizing SharePoint's OOTB events with PnP commands to trigger automated actions eliminates delays inherent in daily synchronization tasks. This approach not only enhances operational efficiency but also improves user experience by ensuring that permissions and other configurations are consistently up-to-date. This strategy ensures more efficient management of SharePoint systems, minimizing delays and boosting overall operational effectiveness.

 If you have any questions you can reach out our SharePoint Consulting team here.

August 8, 2024

Resolving Power Automate Flow Trigger Issues when Migrating Items to a SharePoint List

Introduction:

Automation in SharePoint using Power Automate can significantly streamline processes and enhance productivity. However, certain scenarios, such as bulk item migrations, can lead to unintended behaviors. This blog post will share a recent problem encountered with an automated flow triggered by item creation in a SharePoint list. We will also walk you through the steps we took to resolve this issue effectively.

Problem:

We had set up an automated flow in Power Automate that trigger whenever a new item is created in a SharePoint list. Before migrating many items, we turned off this flow to prevent it from triggering for each migrated item. After completing the migration and reactivating the flow, we observed an unexpected behavior, the flow triggered for all the newly migrated items due to data stored in the browser cache. This resulted in uneven and unwanted executions of the flow.

Steps to the solution:

To avoid this issue in future migrations, we followed an approach that ensures the flow does not trigger unintentionally during bulk item migrations. Here are the steps:


Step 1: Export the Flow

Before starting the migration process, export the existing flow to your local machine. This step ensures that you have a backup of the flow configuration and can easily restore it later.

  1. Open Power Automate.
  2. Navigate to the flow which you want to export.
  3. Select the flow and open it.
  4. Select "Export", then click on the "Package (.zip)"
  5. In the opened "Package details" section, Give the Name of the package.
  6. Click on the exported .zip file and download it to your computer.

     



Step 2: Delete the Existing Flow

With the flow exported and safely stored, proceed to delete the existing flow. This step prevents any triggers from occurring during the migration process.
  1. Navigate to the flow which you want to delete.
  2. Click on “Delete” and it will ask for confirmation. 


Step 3: Migrate the Items

Now that the flow has been deleted, proceed with migrating the items to the SharePoint list. Since the flow is not present, it will not trigger during this process.


Step 4: Recreate the Flow by Importing the Zip File

After completing the migration, recreate the flow by importing the previously exported .zip file. This ensures that the flow is restored to its original configuration.
  1. Navigate to the location where you want to Import.
  2. Click on "Import" -> Import Package (Legacy).
  3. Upload the .zip file that you exported earlier; it will take some time to complete the process.
  4. In Review Package Content – click on the "Update" link from IMPORT SETUP.
  5. It will open an "Import setup" panel, in the Setup field we need to select the "Create as new" option and then click on the Save button.
  6. Click on the Import button. [Note: It will take some time to Import the file, so please do not navigate away]
  7. Once the Import is completed then you will get a successfully imported message.


Step 5: Verify and Reactivate the Flow Once the flow is successfully imported, verify its configuration to ensure everything is set up correctly. Then, reactivate the flow.
  1. Locate the newly imported flow.
  2. Ensure the configuration is correct and click on "Turn on" to reactivate it. 

Conclusion:

By following these steps, you can effectively manage your automated flows in Power Automate and avoid unintended triggers during bulk item migrations. Exporting and deleting the flow before migration, and then recreating it afterward, ensures that your automation behaves as expected and maintains data integrity. This method provides a reliable solution to prevent the issues caused by browser cache and uneven flow triggering.

Implementing this approach will save you time and effort, ensuring a smooth migration process without disrupting your automated workflows.






If you have any questions you can reach out our SharePoint Consulting team here.