Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Purge-Failures-Caused-by-Custom-Plugin.md #5374

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# How to Identify Purge Failures Caused by a Custom Plugin

## When to Start the Investigation
Start investigating if the "Retention Failed" count increases within the pending delete state.

## Steps to Follow:

### 1. Verify if the Failure is Due to a Custom Plugin
Confirm whether the failure is triggered by a custom plugin that executes on the "Delete" message for the specific entities. Check the `RetentionFailureDetail` table to see if the `OperationID` matches `RetentionOperationId`, and the `OperationType` equals `30` (indicating Purge).

```
<OrgUrl>/api/data/v9.0/retentionfailuredetails?$filter=operationid%20eq%20%27<RetentionOperationID>%27%20and%20operation%20eq%2030
```

Copy link
Member

@phecke phecke Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing image. Add image to the ./media folder and update the image path in the markdown reference.

![image.png](/.attachments/image-d4cfc4a8-f295-4083-8128-30e533cc6721.png)

We can also review the Plugin Trace Logs to identify the failure point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing image

![image2.PNG](/.attachments/image2-d68cc343-d8d4-4ea7-9409-bd09ac08daea.PNG)
### 2. Bypassing the Validation for Deletes Triggered by Retention
If you want to bypass validation for deletes initiated during retention, modify your plugin logic as shown below:

```csharp
class SampleDeletePlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
if (IsDeleteDueToRetention(serviceProvider))
{
// Insert logic to handle deletes triggered by retention
}
else
{
// Insert logic to handle regular deletes not related to retention
}
}

private bool IsDeleteDueToRetention(IServiceProvider serviceProvider)
{
IPluginExecutionContext currentContext = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
while (currentContext != null)
{
if (currentContext.InputParameters.TryGetValue<bool>("DeleteInvokedByRetention", out var isDeleteByRetention) && isDeleteByRetention)
{
return true;
}
}
return false;
}
}
```

### 3. Apply Similar Validation for Retain Messages
To apply similar validation for retention, you can create a plugin on the "Retain" message. Follow the same approach as described above for handling retention-based logic, but ensure the logic is suited to the "Retain" message.

### 4. Additional Resources
- [Reference to Long-term data retention
](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/long-term-retention?tabs=sdk#custom-logic-while-retention-executes)
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ public EntityCollection GetActivePolicies(IOrganizationService orgService)

---

## Handle Purge Failures due to Custom Plugin
[Purge Failures due to Custom Plugin](./Purge-Failures-Caused-by-Custom-Plugin.md)

### More examples of FetchXML query strings

This code sample illustrates using a FetchXML statement to retrieve all paused retention policies for an email.
Expand Down